Operating-system support for job control facilities comes in several parts: notably a way to stop and restart execution of a process, and a way to reserve a terminal device for use by one process group at a time. A command processor such as the C shell uses these facilities to grant control of a terminal to one `foreground' job at a time, and to move jobs between the `foreground' and `background'.
To stop a process, send it a stop signal (e.g., SigTStp; see page
). To restart a stopped process, send it a continue
signal (SigCont). While a process is stopped, none of its threads
execute. However, intramachine remote procedure calls, including those to
OS procedures, performed before the process was stopped keep executing up
until the return. Normally a stop/start cycle need not and does not
affect the state of a process. A process can if it desires perform
`clean-up' computations before being stopped and after being restarted.
To clean up beforehand, it handles SigTStp (and possibly SigTTOu and
SigTTIn), performs its clean-up, and then sends itself SigStop. To clean
up after being restarted, it handles SigCont.
Stop and continue signals provide the basic mechanism for job control, but
there needs to be a quick way for a user at a terminal to request that the
current job be stopped as well as a mechanism to make sure that a
background job doesn't interfere with the use of the terminal by the
foreground job. For this reason, there is a distinguished process group
associated with each terminal device. Only processes in that process
group can read and write the terminal; a background process (one not in
the group), will normally receive a SigTTIn or SigTTOu signal if it tries
to read or write its control terminal (see Read and Write starting on page
for more details). Also, the terminal has a mode such
that when the user types a particular key (normally Control-Z), the
terminal sends a SigTStp signal to the distinguished process group (see
the IOCtl interface and tty(4)).
There are a few more details relevant to job control. A command
interpreter process implementing job control needs to find out when the
current foreground job stops; it uses the procedure WaitForChild (see page
) to find out when a specific child process has stopped or
terminated. The command interpreter needs to reset the distinguished
process group of the control terminal to itself or to a new foreground
job; it uses SetDevPGRP for this (see page
).