WAITing for specific process
Doug Gwyn <gwyn>
gwyn at brl-tgr.ARPA
Sun Aug 4 12:23:04 AEST 1985
> The wait() system call returns the process id of zombie child, but a
> process may have more than one of these outstanding at a time. Wait()
> is free (it appears) to return the pid of any of these zombie children.
> What if you want to wait for a particular child? For example, one might
> pass the pid of a process to be waited for. It's clear that the way
> it works now is useful, but there times it really gets in the way.
> An example of this is the library functions popen/pclose, which
> generate and wait for a child, possibly discarding a zombie that was
> to be waited for later. Any suggestions as to what to do or why this
> facility isn't provided?
The facility IS provided, to some degree:
void
waitfor( pid ) /* wait for process to exit */
int pid; /* ID of process to wait on */
{
extern unsigned sleep();
#define DELAY 2 /* test interval, in seconds */
while ( kill( pid, 0 ) == 0 )
sleep( (unsigned)DELAY );
}
If one wants to pick up the exit status, then one runs into the
problem you mention, which is the possible consumption of the exit
statuses of other zombies. One solution would be to have your
process keep track of all the processes it has created, in a single
code module, and stash the spurious zombie statuses for later calls
on waitfor(). The only children your process should have other than
those it created itself are the ones it is given by the shell when
it is last in a pipeline. It doesn't matter if you eat those zombies.
More information about the Comp.unix.wizards
mailing list