MONITOR option is set, an interactive shell associates a
job with each pipeline. It keeps a table of current jobs,
printed by the
jobs command, and assigns them small integer
numbers. When a job is started asynchronously with
&, the shell
prints a line which looks like:
indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process id was 1234.
If a job is started with
&!, then that job is
immediately disowned. After startup, it does not have a place in the job
table, and is not subject to the job control features described here.
If you are running a job and wish to do something else you may hit the
key ^Z (control-Z) which sends a
TSTP signal to the current
job. The shell will then normally indicate that the job has been
suspended, and print another prompt. You can then manipulate the
state of this job, putting it into the background with the
command, or run some other commands and then eventually bring the job
back into the foreground with the foreground command
^Z takes effect immediately and is like an interrupt in that
pending output and unread input are discarded when it is typed.
A job being run in the background will suspend if it tries to read from
the terminal. Background jobs are normally allowed to produce output,
but this can be disabled by giving the command
stty tostop. If
you set this tty option, then background jobs will suspend when they try
to produce output, like they do when they try to read input.
There are several ways to refer to jobs in the shell. A job can be referred to by the process id of any process of the job or by one of the following:
The shell learns immediately whenever a process changes state. It
normally informs you whenever a job becomes blocked so that no further
progress is possible. If
notify is not set, it waits until just
before it prints a prompt before it informs you.
When the monitor mode is on, each background job that completes triggers
any trap set for
When you try to leave the shell while jobs are running or suspended, you
will be warned that `You have suspended (running) jobs'. You may
jobs command to see what they are. If you do this or
immediately try to exit again, the shell will not warn you a second
time; the suspended jobs will be terminated, and the running jobs will
be sent a
SIGHUP signal. To avoid having the shell terminate the
running jobs, either use the
nohup(1) command or the
disown builtin (see section Shell Builtin Commands).
QUIT signals for an invoked command are
ignored if the command is followed by
& and the job
option is not active. Otherwise, signals have the values inherited by
the shell from its parent (but See section Functions, for the
TRAPxxx special functions).
Go to the first, previous, next, last section, table of contents.