Parent detect when forked processes exit

Feb 11, 2013 at 4:55am
I'm trying to write a program that will fork a number of children processes that will run concurrently and exit after some randomized amount of time. My problem is that I need the parent to spit out a message each time a child exits as follows:

"Daughter PID EXITED after (t) seconds."

with actual values for PID and (t). How would I make the parent detect when an exit has occurred and then display the message?
Last edited on Feb 11, 2013 at 4:57am
Feb 11, 2013 at 9:42am
You may want to take a look at waitpid with the WNOHANG option:
http://pubs.opengroup.org/onlinepubs/007908799/xsh/wait.html
Feb 11, 2013 at 3:10pm
Awesome, thanks!
Mar 8, 2013 at 11:36pm
You may also think about SIGCHLD handling if your parent process shouldn't poll for terminating childs.
Topic archived. No new replies allowed.