Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!philabs!prls!amdimage!amdcad!decwrl!decvax!genrad!panda!talcott!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.unix-wizards Subject: Re: WAITing for specific process Message-ID: <406@brl-tgr.ARPA> Date: Sat, 3-Aug-85 22:23:04 EDT Article-I.D.: brl-tgr.406 Posted: Sat Aug 3 22:23:04 1985 Date-Received: Tue, 6-Aug-85 06:01:35 EDT References: <106@ihuxj.UUCP> Distribution: net Organization: Ballistic Research Lab Lines: 32 > 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.