Builtins builtin commands bg, fg, jobs, kill, disown, suspend, autoresumeVariables 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. This is acomplished jointly by the system's terminal driver and Bash.
Bash associates a job with each pipeline. A table of currently executing jobs, is listed using the jobs command.
When Bash starts a job asynchronously ( using an & at the end of the command line),
it displays the job number and last process in the pipeline associated with this job for example:
[1] 25647
All of the processes in a single pipeline are members of the same job.
Bash uses the job abstraction as the basis for job control.
The operating system maintains a current terminal process group ID, 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.
Background processes are those whose process group ID differs from the
terminal's and do not receive keyboard-generated signals.
Background processes which attempt to read from (write to) the terminal are sent a sigTTIN
(sigTTOU) signal, which suspends the process, unless previoulsly trapped.
Typing the delayed suspend character
(typically ^Y ) while a process is running in the foreground, causes the process to be suspended
when it attempts to read input from the terminal
then control to be returned to Bash.
Typing the susp character (typically ^Z, Control-Z)
causes the process to be suspended and returns control to Bash.
susp takes effect immediately, and causes pending output and typeahead to be discarded.
bg to continue it in the background
fg to continue it in the foreground
kill
% introduces a Job name or Job number n may be referred to as %n.
%% and %+ refer to the current job, which is the last job stopped while it was in the foreground or started in the background.
%- previous job may be referenced using
. jobs flags 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, %ce refers
to a stopped ce job. Using %?ce, on the
other hand, refers to any job containing the string ce in
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 bg %1
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.
If the -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 are terminated, if there are no intervening commands.
> gzip 0908*
^Z
[1]+ Suspended gzip 0908*
> bg gzip
[1]+ gzip 0908* &
> jobs
[1]+ Running gzip 0908* &
> jobs
[1]+ Done gzip 0908*
Go to the first, previous, next (restricted), last section, table of contents A>.