ptg10805159
Section 9.8 Job Control 299
Most applications don’t call these two functions directly.Instead, the functions are
normally called by job-control shells.
Thetcgetsidfunction allows an application to obtain the process group ID for the
session leader given a file descriptor for the controlling TTY.
#include <termios.h>
pid_t tcgetsid(intfd);
Returns: session leader’s process group ID if OK,−1 on error
Applications that need to manage controlling terminals can usetcgetsid to
identify the session ID of the controlling terminal’s session leader (which is equivalent
to the session leader’s process group ID).
9.8 Job Control
Job control is a featurethat was added to BSD around 1980. This featureallows us to
start multiple jobs (groups of processes) from a single terminal and to control which
jobs can access the terminal and which jobs arerun in the background. Job control
requires three forms of support:
- A shell that supports job control
- The terminal driver in the kernel must support job control
- The kernel must support certain job-control signals
SVR3 provided a different form of job control calledshell layers.The BSD form of job control,
however,was selected by POSIX.1 and is what we describe here. In earlier versions of the
standard, job control support was optional, but POSIX.1 now requires platforms to support it.
From our perspective, when using job control from a shell, we can start a job in
either the foreground or the background. A job is simply a collection of processes, often
apipeline of processes. For example,
vi main.c
starts a job consisting of one process in the foreground. The commands
pr *.c | lpr &
make all &
start two jobs in the background. All the processes invoked by these background jobs
are in the background.
As we said, to use the features provided by job control, we need to use a shell that
supports job control. With older systems, it was simple to say which shells supported
job control and which didn’t. The C shell supported job control, the Bourne shell didn’t,
and it was an option with the Korn shell, depending on whether the host supported job
control. But the C shell has been ported to systems (e.g., earlier versions of System V)
that don’t support job control, and the SVR4 Bourne shell, when invoked by the name
jshinstead ofsh,supports job control. The Korn shell continues to support job control