I wasn't sure if I could count on it that queued jobs would be executed in the order presented by showq
, but after some more research, it certainly looks like it.
The queue printed by showq
has the following format:
ACTIVE JOBS--------
[table headers]
[listing of active jobs]
IDLE JOBS--------
[table headers]
[listing of idle jobs]
BLOCKED JOBS----------
[table headers]
[listing of blocked jobs]
Based on this format, I came up with the following bash script to find a job's place in the idle section of the queue, given the job's id:
job=$1
idlestart=`showq | grep "IDLE JOBS" -n | cut -d: -f1`
jobline=`showq | grep -n $job | cut -d: -f1`
place=`expr $jobline - $idlestart - 2`
echo "Idle Jobs section starts at line $idlestart"
echo "Job $job at line $jobline"
echo "Place in queue: $place"
Example output:
$ ./placeinq 6565618
Idle Jobs section starts at line 343
Job 6565618 at line 387
Place in queue: 42