6.14. Job ControlJob control allows you to suspend and resume the execution of a process begun from the Bash command line. Typing a Control-Z while a process is running will suspend it. You can then use the bg or fg shell commands to resume it in the background or foreground, respectively, as described in Figures 6-48 and 6-49. To see all jobs associated with the current shell, use the jobs built-in (Figure 6-46).
6.14.1. Specifying a JobEach of the job control commands (bg, fg, and kill) requires that a job be specified upon which to act. Figure 6-47 shows the forms available to specify a Bash job.
The specifier must uniquely identify a job. If more than one job matches the specifier, Bash reports an error. 6.14.2. bgFigure 6-48 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 bash | ul -tdumb > bash.txt ...start in foreground. ^Z ...suspend it. [1] + Stopped man bash | ul -tdumb > bash.txt $ bg %1 ...resume it in background. [1] man bash | ul -tdumb > bash.txt& $ jobs ...list current jobs. [1] + Running man bash | ul -tdumb > bash.txt $ _ 6.14.3. fgFigure 6-49 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 bash | ul -tdumb > bash.txt & ...start another. [2] 27144 $ jobs ...list the current jobs. [2] + Running man bash | ul -tdumb > bash.txt & [1] - Running sleep 1000 & $ fg %ma ...bring job to foreground. man bash | ul -tdumb > bash.txt ...command is redisplayed. $ _ 6.14.4. killUse the kill built-in to send a signal to a job (Figure 6-50).
|