Skip to content

Managing Jobs

Exercises

  1. Submit a long job, then cancel it

Submit a job that sleeps for 1 hour. Confirm it is running or pending with squeue --me, then cancel it with scancel. Verify it is gone from the queue.

Hint / Solution
sbatch --time=01:00:00 --wrap="sleep 3600" --job-name=cancel_test
squeue --me
scancel <jobid>
squeue --me
  1. Hold a pending job and release it

Submit a job in the held state using --hold. Verify its pending reason shows (JobHeldUser) in squeue. Then release it with scontrol release and confirm it returns to normal pending status.

Hint / Solution
sbatch --hold --time=00:10:00 --wrap="echo 'Released and running'" --job-name=hold_test
squeue --me -o "%.8i %.20j %.2t %R"
# Should show PD with reason (JobHeldUser)

scontrol release <jobid>
squeue --me -o "%.8i %.20j %.2t %R"
# Should now show PD with (Priority) or (Resources), or R if running
  1. Modify a pending job's time limit

Submit a job with a 1-hour time limit in held state. Before releasing it, use scontrol update to change the time limit to 2 hours. Verify the change with scontrol show job, then release the job.

Hint / Solution
sbatch --hold --time=01:00:00 --wrap="sleep 60" --job-name=modify_test
scontrol update JobId=<jobid> TimeLimit=02:00:00
scontrol show job <jobid> | grep TimeLimit
# Should show TimeLimit=02:00:00
scontrol release <jobid>
  1. Cancel only pending jobs

Submit three jobs: two short ones that will likely start running and one requesting large resources that will pend. Use scancel with --state=PENDING to cancel only the pending job while leaving the running ones alone.

Hint / Solution
sbatch --time=00:10:00 --wrap="sleep 300" --job-name=runner1
sbatch --time=00:10:00 --wrap="sleep 300" --job-name=runner2
sbatch --time=00:10:00 --mem=500G --wrap="sleep 60" --job-name=will_pend

squeue --me
scancel --me --state=PENDING
squeue --me
# Running jobs should still be there; pending job should be gone

# Clean up
scancel --me

References