如何在Slurm中取消作业ID大于特定数值的指定作业?
Got it, let's break this down so you can safely cancel only the problematic jobs without touching your running or correct queued ones.
Step 1: Lock in your cutoff job ID
First, figure out the maximum job ID you want to keep. Let's say that number is 12345—you'll cancel every job with an ID higher than this value.
Step 2: Preview the jobs you'll cancel (critical first step!)
Never run a cancel command blind. Use this to list exactly which job IDs match your criteria, so you can verify no valid jobs are included:
squeue -u $USER -h -o "%i" | awk '$1 > 12345'
Here's what each part does:
-u $USER: Restricts results to only your jobs (avoids messing with others' work)-h: Hides the header row so we only get raw job IDs-o "%i": Tellssqueueto output nothing but job IDsawk '$1 > 12345': Filters the list to only include IDs larger than your cutoff
Double-check this output—make sure none of your running or correct queued jobs show up here.
Step 3: Cancel the targeted jobs
Once you're confident the preview is right, pipe the filtered IDs to scancel to remove them:
squeue -u $USER -h -o "%i" | awk '$1 > 12345' | xargs scancel
Bonus: Only cancel pending (not running) jobs
If you want an extra layer of safety to leave running jobs untouched (even if their IDs are above the cutoff), modify the command to target only jobs in the "Pending" (PD) state:
squeue -u $USER -h -o "%i %t" | awk '$1 > 12345 && $2 == "PD"' | awk '{print $1}' | xargs scancel
We add -o "%i %t" to pull both job ID and state, then filter for pending jobs before passing to scancel.
内容的提问来源于stack exchange,提问作者Mona Jalilvand

