Managing Jobs
Exercises¶
- 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
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sbatch --time=01:00:00 --job-name=val_mg1 --output=/dev/null --wrap='sleep 3600'
Submitted batch job 42
$ squeue --me
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
42 batch val_mg1 ec2-user R 0:02 1 batch-dy-compute-1
$ scancel 42
$ squeue --me
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
- 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
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sbatch --hold --time=00:10:00 --job-name=val_mg2 --output=/dev/null --wrap='echo released'
Submitted batch job 42
$ squeue --me -o '%.8i %.20j %.2t %R'
JOBID NAME ST NODELIST(REASON)
42 val_mg2 PD (JobHeldUser)
$ scontrol release 42
$ squeue --me -o '%.8i %.20j %.2t %R'
JOBID NAME ST NODELIST(REASON)
- 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>
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
- 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
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ sbatch --time=00:05:00 --job-name=val_mg4a --output=/dev/null --wrap='sleep 60'
Submitted batch job 42
$ sbatch --time=00:05:00 --job-name=val_mg4b --output=/dev/null --wrap='sleep 60'
Submitted batch job 43
$ sbatch --hold --time=00:05:00 --job-name=val_mg4p --output=/dev/null --wrap='sleep 60'
Submitted batch job 44
$ squeue --me
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
44 batch val_mg4p ec2-user PD 0:00 1 (JobHeldUser)
42 batch val_mg4a ec2-user R 0:01 1 batch-dy-compute-1
43 batch val_mg4b ec2-user R 0:01 1 batch-dy-compute-2
$ scancel --me --state=PENDING
$ squeue --me
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
42 batch val_mg4a ec2-user R 0:03 1 batch-dy-compute-1
43 batch val_mg4b ec2-user R 0:03 1 batch-dy-compute-2
$ scancel --me