< Day Day Up > |
9.18. TC Shell Job ControlJob control is a powerful feature of the TC shell that allows you to run programs, called jobs, in the background or foreground. Normally, a command typed at the command line is running in the foreground and will continue until it has finished. If you have a windowing program, job control may not be necessary, because you can simply open another window to start a new task. On the other hand, with a single terminal, job control is a very useful feature. For a list of job commands, see Table 9.20.
9.18.1 The jobs Command and the listjobs VariableThe tcsh built-in jobs command displays the programs that are currently active and either running or suspended in the background. Running means the job is executing in the background. When a job is suspended, it is stopped; it is not in execution. In both cases, the terminal is free to accept other commands. If you attempt to exit the shell while jobs are stopped, the warning, "There are suspended jobs" will appear on the screen. When you attempt to exit immediately a second time, the shell will go ahead and terminate the suspended jobs. You set the tcsh built-in listjobs variable if you want to automatically print a message when you suspend a job. Example 9.98.(The Command Line) 1 > jobs 2 [1] + Suspended vi filex [2] - Running sleep 25 3 > jobs -l [1] + 355 Suspended vi filex [2] - 356 Running sleep 25 4 [2] Done sleep 25 5 > set listjobs = long > sleep 1000 Press Ctrl-Z to suspend job [1] + 3337 Suspended sleep 1000 > 6 > set notify EXPLANATION
9.18.2 Foreground and Background CommandsThe fg command brings a background job into the foreground. The bg command starts a suspended job running in the background. A percent sign and the number of a job can be used as arguments to fg and bg if you want to select a particular job for job control. Example 9.99.1 > jobs 2 [1] + Suspended vi filex [2] - Running cc prog.c -o prog 3 > fg %1 vi filex (vi session starts) 4 > kill %2 [2] Terminated c prog.c -o prog 5 > sleep 15 (Press ^z) Suspended 6 > bg [1] sleep 15 & [1] Done sleep 15 EXPLANATION
9.18.3 Scheduling JobsThe sched built-in command allows you to create a list of jobs that will be scheduled to run at some specific time. The sched command, without arguments, displays a numbered list of all the scheduled events. It sets times in the form hh:mm (hour:minute) where hour can be in military or 12-hour AM/PM format. Time can also be specified as a relative to the current time with a + sign. With a – sign, the event is removed from the list.[8]
FORMAT sched sched [+]hh:mm command sched -n Example 9.100.1 > sched 14:30 echo '^G Time to start your lecture!' 2 > sched 5PM echo Time to go home. 3 > sched +1:30 /home/ellie/scripts/logfile.sc 4 > sched 1 17:47 /home/scripts/logfile.sc 2 5PM echo Time to go home. 3 14:30 echo '^G Time to start your lecture!' 5 > sched -2 > sched 1 17:47 /home/scripts/logfile.sc 2 14:30 echo '^G Time to start your lecture!' EXPLANATION
|
< Day Day Up > |