Author: Eric Latham
Email: [email protected]
I initially wrote this program for a final project in a UNIX systems programming course taught by Dr. Purushotham Bangalore at UAB , and then I polished it.
This program is a simple job scheduler written in C that executes a specified number of non-interactive, background-compatible jobs concurrently, redirecting the output and error streams of each job to <jobID>.out
and <jobID>.err
, respectively.
-
User input is handled flexibly with respect to whitespace.
-
The main program error stream is redirected to
<executable>.err
to avoid interrupting user input.
Divide the main program tasks into threads and execute jobs in new processes.
Handle user input; insert new jobs and respond to commands.
Execute waiting jobs concurrently.
- while true:
- if queue is not empty and number of jobs working < concurrency:
- take the next job off the queue
- use a new thread to:
- increment number of jobs working
- update job as working
- use a new process to complete job
- wait for the process to finish
- update job as complete
- decrement number of jobs working
- wait a second before next iteration
Use any of the following commands:
make
gcc -Wall -lpthread -o job_scheduler job_scheduler.c helpers.c
Use the following command:
./job_scheduler CONCURRENCY
CONCURRENCY
is an integer clipped to the range[1, 8]
-
submit COMMAND [ARGS]
- Add a job with the specified command and arguments to the job queue to be started as soon as possible and print the job's job ID to
stdout
.
- Add a job with the specified command and arguments to the job queue to be started as soon as possible and print the job's job ID to
-
showjobs
- List all jobs that are currently waiting or working by displaying each job's job ID and status.
-
submithistory
- List all jobs that were completed during the current session by displaying each job's job ID, thread ID (the ID of the thread the job was completed in), command and arguments, start time, end time, and exit status.