<s>
In	O
computing	O
,	O
a	O
parent	B-Operating_System
process	I-Operating_System
is	O
a	O
process	O
that	O
has	O
created	O
one	O
or	O
more	O
child	O
processes	O
.	O
</s>
<s>
In	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
,	O
every	O
process	O
except	O
(	O
the	O
swapper	O
)	O
is	O
created	O
when	O
another	O
process	O
executes	O
the	O
fork( )	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
The	O
process	O
that	O
invoked	O
fork	B-Language
is	O
the	O
parent	B-Operating_System
process	I-Operating_System
and	O
the	O
newly	O
created	O
process	O
is	O
the	O
child	B-Operating_System
process	I-Operating_System
.	O
</s>
<s>
Every	O
process	O
(	O
except	O
process	B-Application
0	I-Application
)	O
has	O
one	O
parent	B-Operating_System
process	I-Operating_System
,	O
but	O
can	O
have	O
many	O
child	O
processes	O
.	O
</s>
<s>
The	O
operating	B-Operating_System
system	I-Operating_System
kernel	I-Operating_System
identifies	O
each	O
process	O
by	O
its	O
process	B-Operating_System
identifier	I-Operating_System
.	O
</s>
<s>
is	O
a	O
special	O
process	O
that	O
is	O
created	O
when	O
the	O
system	O
boots	O
;	O
after	O
forking	O
a	O
child	B-Operating_System
process	I-Operating_System
becomes	O
the	O
swapper	O
process	O
(	O
sometimes	O
also	O
known	O
as	O
the	O
"	O
idle	B-Algorithm
task	I-Algorithm
"	O
)	O
.	O
</s>
<s>
In	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
,	O
in	O
which	O
there	O
is	O
a	O
very	O
slim	O
difference	O
between	O
processes	O
and	O
POSIX	B-Operating_System
threads	I-Operating_System
,	O
there	O
are	O
two	O
kinds	O
of	O
parent	O
processes	O
,	O
namely	O
real	O
parent	O
and	O
parent	O
.	O
</s>
<s>
Parent	O
is	O
the	O
process	O
that	O
receives	O
the	O
SIGCHLD	B-General_Concept
signal	B-Operating_System
on	O
child	O
's	O
termination	O
,	O
whereas	O
real	O
parent	O
is	O
the	O
thread	O
that	O
actually	O
created	O
this	O
child	B-Operating_System
process	I-Operating_System
in	O
a	O
multithreaded	O
environment	O
.	O
</s>
<s>
For	O
a	O
normal	O
process	O
,	O
both	O
these	O
two	O
values	O
are	O
same	O
,	O
but	O
for	O
a	O
POSIX	B-Operating_System
thread	I-Operating_System
which	O
acts	O
as	O
a	O
process	O
,	O
these	O
two	O
values	O
may	O
be	O
different	O
.	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
maintains	O
a	O
table	O
that	O
associates	O
every	O
process	O
,	O
by	O
means	O
of	O
its	O
process	B-Operating_System
identifier	I-Operating_System
(	O
generally	O
referred	O
to	O
as	O
"	O
pid	O
"	O
)	O
to	O
the	O
data	O
necessary	O
for	O
its	O
functioning	O
.	O
</s>
<s>
When	O
a	O
process	O
terminates	B-Operating_System
its	O
execution	O
,	O
either	O
by	O
calling	O
exit	O
(	O
even	O
if	O
implicitly	O
,	O
by	O
executing	O
a	O
return	O
command	O
from	O
the	O
main	O
function	O
)	O
or	O
by	O
receiving	O
a	O
signal	B-Operating_System
that	O
causes	O
it	O
to	O
terminate	B-Operating_System
abruptly	O
,	O
the	O
operating	B-General_Concept
system	I-General_Concept
releases	O
most	O
of	O
the	O
resources	O
and	O
information	O
related	O
to	O
that	O
process	O
,	O
but	O
still	O
keeps	O
the	O
data	O
about	O
resource	O
utilization	O
and	O
the	O
termination	B-Operating_System
status	I-Operating_System
code	O
,	O
because	O
a	O
parent	B-Operating_System
process	I-Operating_System
might	O
be	O
interested	O
in	O
knowing	O
if	O
that	O
child	O
executed	O
successfully	O
(	O
by	O
using	O
standard	O
functions	O
to	O
decode	O
the	O
termination	B-Operating_System
status	I-Operating_System
code	O
)	O
and	O
the	O
amount	O
of	O
system	O
resources	O
it	O
consumed	O
during	O
its	O
execution	O
.	O
</s>
<s>
By	O
default	O
,	O
the	O
system	O
assumes	O
that	O
the	O
parent	B-Operating_System
process	I-Operating_System
is	O
indeed	O
interested	O
in	O
such	O
information	O
at	O
the	O
time	O
of	O
the	O
child	O
's	O
termination	O
,	O
and	O
thus	O
sends	O
the	O
parent	O
the	O
signal	B-Operating_System
SIGCHLD	B-General_Concept
to	O
alert	O
that	O
there	O
is	O
some	O
data	O
about	O
a	O
child	O
to	O
be	O
collected	O
.	O
</s>
<s>
Such	O
collection	O
is	O
done	O
by	O
calling	O
a	O
function	O
of	O
the	O
wait	O
family	O
(	O
either	O
wait	O
itself	O
or	O
one	O
of	O
its	O
relatives	O
,	O
such	O
as	O
waitpid	B-Operating_System
,	O
waitid	B-Operating_System
or	O
wait4	O
)	O
.	O
</s>
<s>
As	O
soon	O
as	O
this	O
collection	O
is	O
made	O
,	O
the	O
system	O
releases	O
those	O
last	O
bits	O
of	O
information	O
about	O
the	O
child	B-Operating_System
process	I-Operating_System
and	O
removes	O
its	O
pid	O
from	O
the	O
process	O
table	O
.	O
</s>
<s>
However	O
,	O
if	O
the	O
parent	B-Operating_System
process	I-Operating_System
lingers	O
in	O
collecting	O
the	O
child	O
's	O
data	O
(	O
or	O
fails	O
to	O
do	O
it	O
at	O
all	O
)	O
,	O
the	O
system	O
has	O
no	O
option	O
but	O
keep	O
the	O
child	O
's	O
pid	O
and	O
termination	O
data	O
in	O
the	O
process	O
table	O
indefinitely	O
.	O
</s>
<s>
If	O
the	O
program	O
is	O
expected	O
to	O
create	O
many	O
child	O
processes	O
that	O
may	O
execute	O
asynchronously	O
and	O
terminate	B-Operating_System
in	O
an	O
unpredictable	O
order	O
,	O
it	O
is	O
generally	O
good	O
to	O
create	O
a	O
handler	O
for	O
the	O
SIGCHLD	B-General_Concept
signal	B-Operating_System
,	O
calling	O
one	O
of	O
the	O
wait-family	O
function	O
in	O
a	O
loop	O
,	O
until	O
no	O
uncollected	O
child	O
data	O
remains	O
.	O
</s>
<s>
It	O
is	O
possible	O
for	O
the	O
parent	B-Operating_System
process	I-Operating_System
to	O
completely	O
ignore	O
the	O
termination	O
of	O
its	O
children	O
and	O
still	O
not	O
create	O
zombies	O
,	O
but	O
this	O
requires	O
the	O
explicit	O
definition	O
of	O
a	O
handler	O
for	O
SIGCHLD	B-General_Concept
through	O
a	O
call	O
to	O
sigaction	O
with	O
the	O
special	O
option	O
flag	O
SA_NOCLDWAIT	O
.	O
</s>
<s>
Orphan	O
processes	O
are	O
an	O
opposite	O
situation	O
to	O
zombie	O
processes	O
,	O
referring	O
to	O
the	O
case	O
in	O
which	O
a	O
parent	B-Operating_System
process	I-Operating_System
terminates	B-Operating_System
before	O
its	O
child	O
processes	O
,	O
which	O
are	O
said	O
to	O
become	O
"	O
orphaned	O
"	O
.	O
</s>
<s>
Unlike	O
the	O
asynchronous	O
child-to-parent	O
notification	O
that	O
happens	O
when	O
a	O
child	B-Operating_System
process	I-Operating_System
terminates	B-Operating_System
(	O
via	O
the	O
signal	B-Operating_System
)	O
,	O
child	O
processes	O
are	O
not	O
notified	O
immediately	O
when	O
their	O
parent	O
finishes	O
.	O
</s>
<s>
Instead	O
,	O
the	O
system	O
simply	O
redefines	O
the	O
"	O
parent	O
PID	O
"	O
field	O
in	O
the	O
child	B-Operating_System
process	I-Operating_System
's	O
data	O
to	O
be	O
the	O
process	O
that	O
is	O
the	O
"	O
ancestor	O
"	O
of	O
every	O
other	O
process	O
in	O
the	O
system	O
,	O
whose	O
PID	O
generally	O
has	O
the	O
value	O
of	O
1	O
(	O
one	O
)	O
,	O
and	O
whose	O
name	O
is	O
traditionally	O
"	O
init	B-Operating_System
"	O
(	O
except	O
in	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
3.4	O
and	O
above	O
[	O
more	O
info	O
below ]	O
)	O
.	O
</s>
<s>
Thus	O
,	O
it	O
was	O
said	O
that	O
init	B-Operating_System
"	O
adopts	O
"	O
every	O
orphan	B-Operating_System
process	I-Operating_System
on	O
the	O
system	O
.	O
</s>
<s>
A	O
somewhat	O
common	O
assumption	O
by	O
programmers	O
new	O
to	O
UNIX	O
was	O
that	O
the	O
child	O
processes	O
of	O
a	O
terminating	O
process	O
will	O
be	O
adopted	O
by	O
this	O
process	O
's	O
immediate	O
parent	B-Operating_System
process	I-Operating_System
(	O
hence	O
those	O
child	O
processes	O
 '	O
"	O
grandparent	O
"	O
)	O
.	O
</s>
<s>
Such	O
assumption	O
was	O
incorrect	O
unless	O
,	O
of	O
course	O
,	O
that	O
"	O
grandparent	O
"	O
was	O
the	O
init	B-Operating_System
itself	O
.	O
</s>
<s>
After	O
Linux	B-Operating_System
kernel	I-Operating_System
3.4	O
this	O
is	O
no	O
longer	O
true	O
,	O
in	O
fact	O
processes	O
can	O
issue	O
the	O
system	B-Operating_System
call	I-Operating_System
with	O
the	O
PR_SET_CHILD_SUBREAPER	O
option	O
,	O
and	O
as	O
a	O
result	O
they	O
,	O
not	O
process	O
#1	O
,	O
will	O
become	O
the	O
parent	O
of	O
any	O
of	O
their	O
orphaned	O
descendant	O
processes	O
.	O
</s>
<s>
A	O
subreaper	O
fulfills	O
the	O
role	O
of	O
init(1 )	O
for	O
its	O
descendant	O
processes	O
.	O
</s>
<s>
When	O
a	O
process	O
becomes	O
orphaned	O
(	O
i.e.	O
,	O
its	O
immediate	O
parent	O
terminates	B-Operating_System
)	O
then	O
that	O
process	O
will	O
be	O
reparented	O
to	O
the	O
nearest	O
still	O
living	O
ancestor	O
subreaper	O
.	O
</s>
<s>
receive	O
a	O
SIGCHLD	B-General_Concept
signal	B-Operating_System
and	O
will	O
be	O
able	O
to	O
wait(2 )	O
on	O
the	O
process	O
to	O
discover	O
its	O
termination	B-Operating_System
status	I-Operating_System
.	O
</s>
