[Next] [Previous] [Up] [Top] [Contents]

CHAPTER 5 Shells

5.5 Job Control

With the C shell, csh, and many newer shells including some newer Bourne shells, you can put jobs into the background at anytime by appending "&" to the command, as with sh. After submitting a command you can also do this by typing ^Z (Control-Z) to suspend the job and then "bg" to put it into the background. To bring it back to the foreground type "fg".

You can have many jobs running in the background. When they are in the background they are no longer connected to the keyboard for input, but they may still display output to the terminal, interspersing with whatever else is typed or displayed by your current job. You may want to redirect I/O to or from files for the job you intend to background. Your keyboard is connected only to the current, foreground, job.

The built-in jobs command allows you to list your background jobs. You can use the kill command to kill a background job. With the %n notation you can reference the nth background job with either of these commands, replacing n with the job number from the output of jobs. So kill the second background job with "kill %2" and bring the third job to the foreground with "fg %3".

Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]