Children's exit() status

Len Brown lenb at houxs.UUCP
Sat May 21 01:44:35 AEST 1988


Thanks for the numerous replies, here's a summary:

"What is the proper way for a parent process to wait for multiple
 child processes to exit?"

People have warned me that when many children exit simultaneously,
the parent executing wait(2) loop may miss the return status of
some of them.  The truth is that the parent will never miss child
exit status if the loop is constructed properly.

When a child exits, UNIX queues it as a zombie <defunct> until its
parent does a wait(2).  If the parent exits, init will inherit the
children and wait(2) for them.

A simple wait(2) loop would suffice, except sometimes wait(2) returns
when you don't expect it to.  The frequently cited example is when
the parent process is in a pipeline.  The sh(1) may make other pipeline
members children of the parent.  When they exit, they wake up the parent.
So all one has to do is keep a list of the known children's pid's.
When wait(2) returns, check the list to be sure it is a known child
that woke you up.

Len Brown,  AT&T Data Systems Group, Holmdel, NJ.
{ihnp4 etc}!houxs!lenb



More information about the Comp.unix mailing list