Can process do an asynchronous wait?
Michael Meissner
meissner at osf.org
Fri Jun 1 04:32:41 AEST 1990
In article <30343 at cup.portal.com> tms at cup.portal.com (Alexis TMS
Tatarsky) writes:
| If a process forks and execs several child processes, is there any
| way for the parent to detect when the child processes have exited
| or died without having to wait(2) on them. I wrote a program where
| the parent caught SIGCLD but I don't know which child it is which
| died.
If you are using select for other things, another approach than
setting up a signal handler or waitpid with WNOHANG might be to open a
pipe in the parent when doing a fork on each child, and pass the write
end to the child (closing the read end in the child), and keeping the
read end open in the parent (closing the write end in the parent).
When the read file descriptor is available for I/O (assuming the child
does write to the pipe or close the pipe file descriptor), it means
that there are no more writers on the pipe, and that the child died.
Of course the above assume that you have BSD system calls. On System
V, you can either set up a signal handler (note System V, the
semantics of the child death signal are different from BSD), or do the
pipe trick and turn on async mode on the pipe (I don't remember the
ioctl or fcntrl for this in the System V world off hand).
--
Michael Meissner email: meissner at osf.org phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA
Catproof is an oxymoron, Childproof is nearly so
More information about the Comp.unix.questions
mailing list