In a system running Linux 2.6.35+ my program creates many child processes and monitors them. If a child process dies I do some clean-up and spawn the process again. I use signalfd()
to get the SIGCHLD
signal in my process. signalfd
is used asynchronously using libevent
.
When using signal handlers for non-real time signals, while the signal handler is running for a particular signal further occurrence of the same signal has to be blocked to avoid getting into recursive handlers. If multiple signals arrive at that time then kernel invokes the handler only once (when the signal is unblocked).
Is it the same behavior when using signalfd()
as well? Since signalfd
based handling doesn't have the typical problems associated with the asynchronous execution of the normal signal handlers I was thinking kernel can queue all the further occurrences of SIGCHLD
?
Can anyone clarify the Linux behavior in this case ...
Lets say there are many events in the epoll queue which is not yet drained by my process. In that case are you saying that kernel will queue only one read event for SIGCHLD on the signalfd even if n processes die ? About using the waitpid() in a loop, the problem I have with this approach is you only get the exit status of the child process, but loose other information that you would get from struct signalfd_siginfo when you read from signalfd (or siginfo_t when using sigaction). I guess there is no way to get that ? – Manohar Dec 06 '11 at 11:07