CSCI 330 T HE UNIX S YSTEM Shell Job Control
T ODAY ’ S CLASS Unix is multi-user, multi-process OS Shell features to control jobs Unix utilities to manage jobs crontab at batch 2 CSCI The UNIX System
T ERMINOLOGY process is a program in execution process is created every time you run a command each process has a unique process id processes are removed from the system when the command finishes its execution job is a unit of work consists of the commands specified in a single command line A single job may involve several processes, each consisting of an executable program 3 CSCI The UNIX System
J OB C ONTROL T ERMINOLOGY Foreground job: a job that has our immediate attention user has to wait for job to complete Background job: a job that the user does not wait for it runs independently of user interaction Unix shells allow users to: make jobs execute in the background, move jobs from foreground to background, determine their status, and terminate them 4 CSCI The UNIX System
B ACKGROUND J OBS How do we decide which jobs to place in the background? jobs that are run non-interactively jobs that do not require user input Examples: searching the file system for particular kinds of files solving complex equations compiling long programs backing up the file system 5 CSCI The UNIX System
B ACKGROUND J OBS to execute command in the background, put & after it Example: % date; cd projectc; cc gets.c –o gets & [1] % 6 CSCI The UNIX System Job number PID
M ANAGING JOBS display jobs command “jobs” lists your active jobs each job has job number job number with “%” is used to refer to job send job to background bg move job to foreground fg 7 CSCI The UNIX System
S IGNALING JOBS send signal to job with kill command Examples: kill -HUP kill -INT %1 8 CSCI The UNIX System
E NDING JOBS to stop a job kill –STOP resume via “bg” or “fg” command to terminate a job kill kill -INT kill -9 once a job finishes it will display exit status 9 CSCI The UNIX System
S CHEDULING U TILITIES Crontab (= CRON Table) run a job based on a schedule job is executed on a periodic basis at run a job some time in the future batch run a job when system load is low 10 CSCI The UNIX System
P ERIODIC E XECUTION : CRONTAB crontab is based on control file crontab file has 6 columns: minutehourdaymonthweekday command meaning: 1. minute hour day month weekday1-7 (1=Mon,2=Tue, …,7=Sun) 6. commandAny UNIX command “*” means any value 11 CSCI The UNIX System
E XAMPLE : CRONTAB FILE 0 8 * * 1 echo Happy Monday Morning * * 1 echo Meeting at 3pm 0 17 * * 5 $HOME/bin/cleanup.sh 12 CSCI The UNIX System
CRONTAB COMMAND options: -eto edit the control file -lto list the control file -rto remove the control file for superuser -uto edit another user’s control file 13 CSCI The UNIX System
O NE T IME E XECUTION : AT UTILITY Use ‘at’ to run a command or list of commands at a later time Must specify on the command the time and date on which your command to be executed Do not have to be logged in when the commands are scheduled to run Syntax: % at timeDate command 14 CSCI The UNIX System
AT UTILITY Can give as much of date as desired If date/time has passed, command will run instantly In case system was down when it was supposed to run Examples: % at 13:45 Wed % at 01:45 pm Sep 18 % at 09:25 Sep % at 09:25 Sep 18, 2010 % at 11:00 pm tomorrow % at teatime # 4:00 pm 15 CSCI The UNIX System
E XAMPLE : AT UTILITY End input list with cntl-D = end-of-text Remember command runs in batch No output on terminal May get Or just look for side effects % at 08:55 am tomorrow [Return] at> enscript -Pcsl csci330.csh at> commands will be executed using /bin/sh job 1 at Thu Dec 4 08:55: CSCI The UNIX System
AT UTILITIES atq lists user’s scheduled jobs atrm removes specified job from at queue 17 CSCI The UNIX System
BATCH COMMAND batch schedules job to be performed when system load is low same program as “at” Syntax: % batch command on turing: low means load is less than CSCI The UNIX System
S UMMARY Shell Job Control foreground / background jobs periodic scheduling with crontab future execution with at low load execution with batch 19 CSCI The UNIX System