fork + SIGCHLD

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?
yes, you have to or else the process will be zombie/defunct.

http://en.wikipedia.org/wiki/Zombie_process
Signal handlers must not block, so as long as you know waitpid() or wait() won't block, you can use it.

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
sorry.

but what if the parent exits before the child. How will you handle the signal?
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.

Topic archived. No new replies allowed.