7.11. Job ControlThe Korn shell supports the job control commands shown in Figure 7-20.
The next few sections provide a description of each job control facility and examples of their use. 7.11.1. JobsFigure 7-21 describes the jobs shell command.
Here's an example of jobs in action: $ jobs ...no jobs right now. $ sleep 1000 & ...start a background job. [1] 27128 $ man ls | ul -tdumb > ls.txt & ...another bg job. [2] 27129 $ jobs -l ...list current jobs. [2] + 27129 Running man ls | ul -tdumb > ls.txt & [1] - 27128 Running sleep 1000 & $ _ 7.11.2. Specifying a JobThe bg, fg, and kill commands that I'm about to describe allow you to specify a job using one of several forms, as listed in Figure 7-22.
The descriptions that follow contain examples of job specification. 7.11.3. bgFigure 7-23 describes the bg shell command.
In the following example, I started a foreground job and then decided it would be better to run it in the background. I suspended the job using Control-Z and then resumed it in the background. $ man ksh | ul -tdumb > ksh.txt ...start in foreground. ^Z ...suspend it. [1] + Stopped man ksh | ul -tdumb > ksh.txt $ bg %1 ...resume it in background. [1] man ksh | ul -tdumb > ksh.txt& $ jobs ...list current jobs. [1] + Running man ksh | ul -tdumb > ksh.txt $ _ 7.11.4. fgFigure 7-24 describes the fg shell command.
In the following example, I brought a background job into the foreground using fg: $ sleep 1000 & ...start a background job. [1] 27143 $ man ksh | ul -tdumb > ksh.txt & ...start another. [2] 27144 $ jobs ...list the current jobs. [2] + Running man ksh | ul -tdumb > ksh.txt & [1] - Running sleep 1000 & $ fg %ma ...bring job to foreground. man ksh | ul -tdumb > ksh.txt ...command is redisplayed. $ _ 7.11.5. killFigure 7-25 describes the kill shell command.
The following example demonstrates the use of kill: $ man ksh | ul -tdumb > ksh.txt & ...start a bg job. [1] 27160 $ kill -9 %1 ...kill it via a job specifier. [1] + Killed man ksh | ul -tdumb > ksh.txt & $ man ksh | ul -tdumb > ksh.txt & ...start another. [1] 27164 $ kill -KILL 27164 ...kill it via a process ID. [1] + Killed man ksh | ul -tdumb > ksh.txt & $ _ |