Queuing Jobs with qjob
Ed Schaefer and John Spurgeon
Sidebar: Semaphore Options
Most systems administrators are familiar with using the cron facility or the
at command to schedule jobs. Sometimes an attempt is made to schedule
jobs so they don't conflict with one another. For example, it may be necessary
to limit the number of resource-intensive jobs running at the same time to avoid
overloading the system. Or you may need to prevent jobs from simultaneously
accessing a shared resource. This can be challenging, especially if commands
must be run frequently and the time they take to complete is significant and
variable.
One solution is to create a wrapper script that executes commands in series.
This can solve the problem if there is a way to guarantee that only one instance
of the wrapper script executes at a time. However, the situation becomes more
complicated if some jobs need to be run more often than others.
We've developed a shell script called qjob (Listing
1), which places jobs in a FIFO queue and executes them when they are removed
from the queue. This simplifies the scheduling problem and gives you more flexibility
than a wrapper script. With qjob, you can configure how many jobs are allowed
to run at once for a given queue. If only one job can run at a time, then the
queue is analogous to a checkout lane at a supermarket where all the customers
wait while a cashier services the person at the head of the line. If more than
one job can run at once, then the queue behaves like a single line at a bank
with multiple tellers servicing customers simultaneously.
Options
The following options are supported by qjob:
-j job_name -- job_name is an alias that identifies the command
to be executed.
|