< Day Day Up > |
13.4. Job ControlJob control is a powerful feature of the bash shell that allows you to selectively run programs, called jobs, in the background or foreground. A running program is called a process or a job and each process has a process ID number, called the PID. Normally, a command typed at the command line is running in the foreground and will continue until it has finished unless you send a signal by pressing Ctrl-C or Ctrl-\ to terminate it. With job control, you can send a job to the background and let it keep running; you can stop a job by pressing Ctrl-Z, which sends the job to the background and suspends it; you can cause a stopped job to run in the background; you can bring a background job back to the foreground; and you can even kill the jobs you have running in the background or foreground. For a list of job commands, see Table 13.3 on page 782.
13.4.1 Job Control Commands and OptionsBy default, job control is already set (some older versions of UNIX do not support this feature). If disabled, it can be reset by any one of the following commands: FORMAT set -m # set job control in the .bashrc file set -o monitor # set job control in the .bashrc file bash -m -i # set job control when invoking interactive bash Example 13.27.1 $ vi [1]+ Stopped vi 2 $ sleep 25& [2] 4538 3 $ jobs [2]+ Running sleep 25& [1]– Stopped vi 4 $ jobs –l [2]+ 4538 Running sleep 25& [1]– 4537 Stopped vi 5 $ jobs %% [2]+ 4538 Running sleep 25& 6 $ fg %1 7 $ jobs -x echo %1 4537 8 $ kill %1 # or kill 4537 [1]+ Stopped vi Vim: Caught deadly signal TERM Vim: Finished. [1]+ Exit 1 vi EXPLANATION
New jobs OptionsTwo new options were added to the jobs command in bash versions 2.x. They are the –r and –s options. The –r option lists all running jobs, and the –s option lists all stopped jobs. The disown Built-InThe disown built-in command (bash 2.x) removes a specified job from the job table. After the job has been removed, the shell will no longer recognize it as a viable job process and it can only be referenced by its process ID number. |
< Day Day Up > |