Builtins builtin commands
bg, fg, jobs, kill, disown, suspend, autoresume
Variables Variables Bash uses to customize job control.
Job control is the ability to suspend the execution of processes and resume execution at a later time.
When a pipeline started asynchronously ( using an
& at the end of the command line),
Bash associates a job with it
and displays the job number & process ID of the last process in the pipeline for example:
> ls -l |cut -c33- |sort -n |tail -n2 &
All of the processes in a single pipeline are members of the same job.
A table of currently executing jobs, is listed using the
The operating system maintains a terminal process group , whose members
(processes whose process group ID is equal to the current terminal process group ID)
receive keyboard-generated signals such as
sigINT (by default
^C) and are in the foreground.
susp character (typically
causes the process to be suspended immediately,
pending output and typeahead to be discarded.
and control returns to Bash.
delayed suspend character (typically
causes the process to be suspended when it attempts to read input from the terminal then control to be returned to Bash.
bgto continue it in the background
fgto continue it in the foreground
sigTTOU) signal, which suspends the process, (unless previoulsly trapped) ).
% introduces a Job name or number
n may be referred to as
%+refer to the current job, which is the last job stopped while it was in the foreground or started in the background.
jobsflags the current job with a
+, and the previous job with a
A job may also be referred to using a prefix of the name used to start it, or using a substring
that appears in its command line. For example,
to a stopped
ce job. Using
%?ce, on the
other hand, refers to any job containing the string
its command line. If the prefix or substring matches more than one job,
Bash reports an error.
Naming a job can be used to bring it into the foreground:
%1 is a synonym for
fg %1, bringing job 1 from the
background into the foreground. Similarly,
%1 & resumes
job 1 in the background, equivalent to
The shell is notified whenever a job changes state.
Normally, Bash waits until it is about to print a prompt
before reporting changes in a job's status so as to not interrupt any other output.
-b option to the
set builtin is enabled,
Bash reports such changes immediately (see section Set Builtin).
Any trap on
sigCHLD is executed for each child process that exits.
Issuing an exit while the are stopped jobs causes Bash to display the warning:
There are stopped jobs. and the exit is not performed.
jobs displays their status.
A second exit causes the stopped jobs to be terminated, if there are no intervening commands.
> gzip 0908*
+ Suspended gzip 0908*
> bg gzip
+ gzip 0908* &
+ Running gzip 0908* &
+ Done gzip 0908*
bash table of contents