Jun 28, 2011 at 6:55am Jun 28, 2011 at 6:55am UTC
Hi everybody,
I have a question regarding SIGCHLD.
When parent creates new child using fork, is it guaranteed that SIGCHLD will be delivered to parent only once when child exits?
Is it OK to use waitpid or wait system calls in signal handler routine?
Jun 28, 2011 at 11:49pm Jun 28, 2011 at 11:49pm UTC
Signal handlers must not block, so as long as you know waitpid() or wait() won't block, you can use it.
Jun 29, 2011 at 1:44am Jun 29, 2011 at 1:44am UTC
Hi sharma,
Yes I understand that. However my question was whether I can do it in signal handler routine since the way linux signal handler works. Some suggest setting of only flags in signal handlers and not to call any system calls in the routine. I feel some extent jsmith has answer but I am still not clear
Jun 29, 2011 at 5:21pm Jun 29, 2011 at 5:21pm UTC
sorry.
but what if the parent exits before the child. How will you handle the signal?
Jun 30, 2011 at 4:20am Jun 30, 2011 at 4:20am UTC
Hi sharma,
No need for apologies :). We are all learners.
In that case signal cannot be caught. Children become orphan and gradually be inherited by init.
In my case I keep track of all processes and do waitpid till all children finish the job.