04-23-04 11:34 PM
"Doug Ly" <dmly@sbcglobal.net> writes:
> Hi,
> I've learned that to wait for all the children, we put wait(0) in the main
()
> function.
> But my program gives me weird result. It seems like main() exits when ther
e
> are children are still running.
> Is there a way to check if a program has collected all of its children
> before it can exit?
>
According to wait(3c) man page:
The wait() function will suspend execution of the calling
thread until status information for one of its terminated
child processes is available, or until delivery of a signal
whose action is either to execute a signal-catching function
or to terminate the process. If more than one thread is
suspended in wait(), waitpid(3C), or waitid(2) awaiting ter-
mination of the same process, exactly one thread will return
the process status at the time of the target process termi-
nation. If status information is available prior to the call
to wait(), return will be immediate.
So, if you want to wait for all children, you have to loop (wait sets errno
to ECHILD if there are no existing unwaited-for child processes).
HTH, Dragan
--
Dragan Cvetkovic,
To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer
!!! Sender/From address is bogus. Use reply-to one !!!
[ Post a follow-up to this message ]
|