<s>
In	O
Unix	B-Application
and	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
,	O
job	B-General_Concept
control	I-General_Concept
refers	O
to	O
control	O
of	O
jobs	O
by	O
a	O
shell	B-Application
,	O
especially	O
interactively	O
,	O
where	O
a	O
"	O
job	O
"	O
is	O
a	O
shell	B-Application
's	O
representation	O
for	O
a	O
process	B-Operating_System
group	I-Operating_System
.	O
</s>
<s>
Basic	O
job	B-General_Concept
control	I-General_Concept
features	O
are	O
the	O
suspending	O
,	O
resuming	O
,	O
or	O
terminating	O
of	O
all	O
processes	O
in	O
the	O
job/process	O
group	O
;	O
more	O
advanced	O
features	O
can	O
be	O
performed	O
by	O
sending	O
signals	B-Operating_System
to	O
the	O
job	O
.	O
</s>
<s>
Job	B-General_Concept
control	I-General_Concept
is	O
of	O
particular	O
interest	O
in	O
Unix	B-Application
due	O
to	O
its	O
multiprocessing	B-Operating_System
,	O
and	O
should	O
be	O
distinguished	O
from	O
job	B-General_Concept
control	I-General_Concept
generally	O
,	O
which	O
is	O
frequently	O
applied	O
to	O
sequential	O
execution	O
(	O
batch	B-General_Concept
processing	I-General_Concept
)	O
.	O
</s>
<s>
When	O
using	O
Unix	B-Application
or	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
via	O
a	O
terminal	B-General_Concept
(	O
or	O
terminal	B-Application
emulator	I-Application
)	O
,	O
a	O
user	O
will	O
initially	O
only	O
have	O
a	O
single	O
process	O
running	O
,	O
their	O
interactive	O
shell	B-Application
(	O
it	O
may	O
be	O
login	O
shell	B-Application
or	O
may	O
be	O
not	O
)	O
.	O
</s>
<s>
can	O
easily	O
be	O
accomplished	O
by	O
letting	O
the	O
program	O
take	O
control	O
of	O
the	O
terminal	B-General_Concept
and	O
returning	O
control	O
to	O
the	O
shell	B-Application
when	O
the	O
program	O
exits	O
–	O
formally	O
,	O
by	O
attaching	O
to	O
standard	B-Operating_System
input	I-Operating_System
and	I-Operating_System
standard	I-Operating_System
output	I-Operating_System
to	O
the	O
shell	B-Application
,	O
which	O
reads	O
or	O
writes	O
from	O
the	O
terminal	B-General_Concept
,	O
and	O
catching	O
signals	B-Operating_System
sent	O
from	O
the	O
keyboard	O
,	O
like	O
the	O
termination	O
signal	B-Operating_System
resulting	O
from	O
pressing	O
.	O
</s>
<s>
However	O
,	O
sometimes	O
the	O
user	O
will	O
wish	O
to	O
carry	O
out	O
a	O
task	O
while	O
using	O
the	O
terminal	B-General_Concept
for	O
another	O
purpose	O
.	O
</s>
<s>
A	O
task	O
that	O
is	O
running	O
but	O
is	O
not	O
receiving	O
input	O
from	O
the	O
terminal	B-General_Concept
is	O
said	O
to	O
be	O
running	O
"	O
in	O
the	O
background	O
"	O
,	O
while	O
the	O
single	O
task	O
that	O
is	O
receiving	O
input	O
from	O
the	O
terminal	B-General_Concept
is	O
"	O
in	O
the	O
foreground	O
"	O
.	O
</s>
<s>
Job	B-General_Concept
control	I-General_Concept
is	O
a	O
facility	O
developed	O
to	O
make	O
this	O
possible	O
,	O
by	O
allowing	O
the	O
user	O
to	O
start	O
processes	O
in	O
the	O
background	O
,	O
send	O
already	O
running	O
processes	O
into	O
the	O
background	O
,	O
bring	O
background	B-Operating_System
processes	I-Operating_System
into	O
the	O
foreground	O
,	O
and	O
suspend	O
or	O
terminate	O
processes	O
.	O
</s>
<s>
The	O
concept	O
of	O
a	O
job	O
maps	O
the	O
(	O
shell	B-Application
)	O
concept	O
of	O
a	O
single	O
shell	B-Application
command	O
to	O
the	O
(	O
operating	B-General_Concept
system	I-General_Concept
)	O
concept	O
of	O
the	O
possibly	O
many	O
processes	O
that	O
the	O
command	O
entails	O
.	O
</s>
<s>
Multi-process	O
tasks	O
come	O
about	O
because	O
processes	O
may	O
create	O
additional	O
child	O
processes	O
,	O
and	O
a	O
single	O
shell	B-Application
command	O
may	O
consist	O
of	O
a	O
pipeline	B-Operating_System
of	O
multiple	O
communicating	O
processes	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
command	O
to	O
select	O
lines	O
containing	O
the	O
text	O
"	O
title	O
"	O
,	O
sort	O
these	O
alphabetically	O
,	O
and	O
display	O
the	O
result	O
in	O
a	O
pager	B-General_Concept
.	O
</s>
<s>
Job	B-General_Concept
control	I-General_Concept
allows	O
the	O
shell	B-Application
to	O
control	O
these	O
related	O
processes	O
as	O
one	O
entity	O
,	O
and	O
when	O
a	O
user	O
issues	O
the	O
appropriate	O
key	O
combination	O
(	O
usually	O
)	O
,	O
the	O
entire	O
group	O
of	O
processes	O
gets	O
suspended	O
.	O
</s>
<s>
Jobs	O
are	O
managed	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
as	O
a	O
single	O
process	B-Operating_System
group	I-Operating_System
,	O
and	O
the	O
job	O
is	O
the	O
shell	B-Application
's	O
internal	O
representation	O
of	O
such	O
a	O
group	O
.	O
</s>
<s>
A	O
job	O
can	O
be	O
referred	O
to	O
by	O
a	O
handle	O
called	O
the	O
job	B-General_Concept
control	I-General_Concept
job	O
ID	O
or	O
simply	O
,	O
which	O
is	O
used	O
by	O
shell	B-Application
builtins	O
to	O
refer	O
to	O
the	O
job	O
.	O
</s>
<s>
In	O
informal	O
usage	O
the	O
number	O
may	O
be	O
referred	O
to	O
as	O
the	O
"	O
job	O
number	O
"	O
or	O
"	O
job	O
ID	O
"	O
,	O
and	O
Bash	B-Operating_System
documentation	O
refers	O
to	O
the	O
(%-	O
prefixed	O
)	O
job	O
ID	O
as	O
the	O
jobspec	O
.	O
</s>
<s>
Job	B-General_Concept
control	I-General_Concept
and	O
job	O
IDs	O
are	O
typically	O
only	O
used	O
in	O
interactive	O
use	O
,	O
where	O
they	O
simplify	O
referring	O
to	O
process	B-Operating_System
groups	I-Operating_System
;	O
in	O
scripting	O
PGIDs	O
are	O
used	O
instead	O
,	O
as	O
they	O
are	O
more	O
precise	O
and	O
robust	O
,	O
and	O
indeed	O
job	B-General_Concept
control	I-General_Concept
is	O
disabled	O
by	O
default	O
in	O
bash	B-Operating_System
scripts	I-Operating_System
.	O
</s>
<s>
Job	B-General_Concept
control	I-General_Concept
was	O
first	O
implemented	O
in	O
the	O
C	B-Operating_System
shell	I-Operating_System
by	O
Jim	O
Kulp	O
,	O
then	O
at	O
IIASA	O
in	O
Austria	O
,	O
making	O
use	O
of	O
features	O
of	O
the	O
4.1BSD	O
kernel	O
.	O
</s>
<s>
The	O
KornShell	B-Language
,	O
developed	O
at	O
Bell	O
Labs	O
,	O
adopted	O
it	O
and	O
it	O
was	O
later	O
incorporated	O
into	O
the	O
SVR4	O
version	O
of	O
the	B-Device
Bourne	I-Device
shell	I-Device
,	O
and	O
exists	O
in	O
most	O
modern	O
Unix	B-Application
shells	I-Application
.	O
</s>
<s>
These	O
were	O
modeled	O
after	O
the	O
Korn	B-Language
shell	I-Language
job	B-General_Concept
control	I-General_Concept
commands	O
.	O
</s>
<s>
Typically	O
,	O
the	O
shell	B-Application
keeps	O
a	O
list	O
of	O
jobs	O
in	O
a	O
job	O
table	O
.	O
</s>
<s>
Recall	O
that	O
a	O
job	O
corresponds	O
to	O
a	O
process	B-Operating_System
group	I-Operating_System
,	O
which	O
consists	O
of	O
all	O
the	O
members	O
of	O
a	O
pipeline	B-Operating_System
and	O
their	O
descendants	O
.	O
</s>
<s>
When	O
a	O
session	B-Operating_System
ends	O
when	O
the	O
user	O
logs	B-General_Concept
out	I-General_Concept
(	O
exits	O
the	O
shell	B-Application
,	O
which	O
terminates	O
the	O
session	B-Operating_System
leader	I-Operating_System
process	O
)	O
,	O
the	O
shell	B-Application
process	O
sends	O
SIGHUP	B-General_Concept
to	O
all	O
jobs	O
,	O
and	O
waits	O
for	O
the	O
process	B-Operating_System
groups	I-Operating_System
to	O
end	O
before	O
terminating	O
itself	O
.	O
</s>
<s>
The	O
disown	B-Application
command	O
can	O
be	O
used	O
to	O
remove	O
jobs	O
from	O
the	O
job	O
table	O
,	O
so	O
that	O
when	O
the	O
session	B-Operating_System
ends	O
the	O
child	O
process	B-Operating_System
groups	I-Operating_System
are	O
not	O
sent	O
SIGHUP	B-General_Concept
,	O
nor	O
does	O
the	O
shell	B-Application
wait	O
for	O
them	O
to	O
terminate	O
.	O
</s>
<s>
They	O
thus	O
become	O
orphan	O
processes	O
,	O
and	O
may	O
be	O
terminated	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
,	O
though	O
more	O
often	O
this	O
is	O
used	O
so	O
the	O
processes	O
are	O
adopted	O
by	O
init	B-Operating_System
(	O
the	O
kernel	O
sets	O
their	O
parent	O
process	O
to	O
init	B-Operating_System
)	O
and	O
continue	O
executing	O
as	O
daemons	B-Operating_System
.	O
</s>
<s>
Alternatives	O
to	O
prevent	O
jobs	O
from	O
being	O
terminated	O
include	O
nohup	B-Device
and	O
using	O
a	O
terminal	B-General_Concept
multiplexer	O
.	O
</s>
<s>
This	O
sends	O
the	O
"	O
terminal	B-General_Concept
stop	O
"	O
signal	B-Operating_System
(	O
SIGTSTP	O
)	O
to	O
the	O
process	B-Operating_System
group	I-Operating_System
.	O
</s>
<s>
By	O
default	O
,	O
SIGTSTP	O
causes	O
processes	O
receiving	O
it	O
to	O
stop	O
,	O
and	O
control	O
is	O
returned	O
to	O
the	O
shell	B-Application
.	O
</s>
<s>
However	O
,	O
a	O
process	O
can	O
register	O
a	O
signal	B-Operating_System
handler	I-Operating_System
for	O
or	O
ignore	O
SIGTSTP	O
.	O
</s>
<s>
A	O
process	O
can	O
also	O
be	O
paused	O
with	O
the	O
"	O
stop	O
"	O
signal	B-Operating_System
(	O
SIGSTOP	O
)	O
,	O
which	O
cannot	O
be	O
caught	O
or	O
ignored	O
.	O
</s>
<s>
A	O
job	O
running	O
in	O
the	O
foreground	O
can	O
be	O
interrupted	O
by	O
typing	O
the	O
interruption	O
character	O
(	O
Ctrl-C	B-Device
)	O
.	O
</s>
<s>
This	O
sends	O
the	O
"	O
interrupt	O
"	O
signal	B-Operating_System
(	O
SIGINT	B-General_Concept
)	O
,	O
which	O
defaults	O
to	O
terminating	O
the	O
process	O
,	O
though	O
it	O
can	O
be	O
overridden	O
.	O
</s>
<s>
A	O
stopped	O
job	O
can	O
be	O
resumed	O
as	O
a	O
background	O
job	O
with	O
the	O
bg	B-Device
builtin	O
,	O
or	O
as	O
the	O
foreground	O
job	O
with	O
fg	O
.	O
</s>
<s>
In	O
either	O
case	O
,	O
the	O
shell	B-Application
redirects	O
I/O	B-General_Concept
appropriately	O
,	O
and	O
sends	O
the	O
SIGCONT	O
signal	B-Operating_System
to	O
the	O
process	O
,	O
which	O
causes	O
the	O
operating	B-General_Concept
system	I-General_Concept
to	O
resume	O
its	O
execution	O
.	O
</s>
<s>
In	O
Bash	B-Operating_System
,	O
a	O
program	O
can	O
be	O
started	O
as	O
a	O
background	O
job	O
by	O
appending	O
an	O
ampersand	O
( &	O
)	O
to	O
the	O
command	O
line	O
;	O
its	O
output	O
is	O
directed	O
to	O
the	O
terminal	B-General_Concept
(	O
potentially	O
interleaved	O
with	O
other	O
programs	O
 '	O
output	O
)	O
,	O
but	O
it	O
cannot	O
read	O
from	O
the	O
terminal	B-General_Concept
input	O
.	O
</s>
<s>
A	O
background	B-Operating_System
process	I-Operating_System
that	O
attempts	O
to	O
read	O
from	O
or	O
write	O
to	O
its	O
controlling	O
terminal	B-General_Concept
is	O
sent	O
a	O
SIGTTIN	O
(	O
for	O
input	O
)	O
or	O
SIGTTOU	O
(	O
for	O
output	O
)	O
signal	B-Operating_System
.	O
</s>
<s>
These	O
signals	B-Operating_System
stop	O
the	O
process	O
by	O
default	O
,	O
but	O
they	O
may	O
also	O
be	O
handled	O
in	O
other	O
ways	O
.	O
</s>
<s>
Shells	O
often	O
override	O
the	O
default	O
stop	O
action	O
of	O
SIGTTOU	O
so	O
that	O
background	B-Operating_System
processes	I-Operating_System
deliver	O
their	O
output	O
to	O
the	O
controlling	O
terminal	B-General_Concept
by	O
default	O
.	O
</s>
<s>
In	O
Bash-compatible	O
shells	O
,	O
the	O
kill	B-Operating_System
builtin	O
(	O
not	O
/bin/kill	O
)	O
can	O
signal	B-Operating_System
jobs	O
by	O
job	O
ID	O
as	O
well	O
as	O
by	O
process	B-Operating_System
group	I-Operating_System
ID	I-Operating_System
–	O
sending	O
a	O
signal	B-Operating_System
to	O
a	O
job	O
sends	O
it	O
to	O
the	O
whole	O
process	B-Operating_System
group	I-Operating_System
,	O
and	O
jobs	O
specified	O
by	O
a	O
job	O
ID	O
should	O
be	O
killed	O
by	O
prefixing	O
%	O
.	O
</s>
<s>
kill	B-Operating_System
can	O
send	O
any	O
signal	B-Operating_System
to	O
a	O
job	O
;	O
however	O
,	O
if	O
the	O
intent	O
is	O
to	O
rid	O
the	O
system	O
of	O
the	O
processes	O
the	O
signals	B-Operating_System
SIGKILL	B-General_Concept
and	O
SIGTERM	B-General_Concept
(	O
the	O
default	O
)	O
are	O
probably	O
the	O
most	O
applicable	O
.	O
</s>
