Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I have a SIGCHLD handler installed, is a *blocking* wait on a specific pid still going to work?

I've got something that uses a bunch of async forks to do it's work (underneath a toolkit).

In a specific region of code, I'm forking, and then doing a blocking wait on the child process.

Is the SIGCHLD handler going to gobble the signal before the blocking wait will see it, leaving me potentially hung, or is the wait always going to get something back?

like image 218
iwarford Avatar asked May 01 '12 15:05

iwarford


People also ask

What is the default action when a process receives the signal SIGCHLD?

When a child process stops or terminates, SIGCHLD is sent to the parent process. The default response to the signal is to ignore it. The signal can be caught and the exit status from the child process can be obtained by immediately calling wait(2) and wait3(3C).

What is the use of SIGCHLD signal?

Sends a SIGCHLD signal to the parent process to indicate that the child process has ended. Saves the exit status of the child process so that the parent process can identify which child process (by process ID) ended and its exit status.

Does exit send SIGCHLD?

Upon exit, the child leaves an exit status that should be returned to the parent. So, when the child finishes it becomes a zombie. Whenever the child exits or stops, the parent is sent a SIGCHLD signal.

What is Sigaction in C?

The sigaction() function allows the calling process to examine and/or specify the action to be associated with a specific signal.


1 Answers

A SIGCHLD handler gets fired on the event, the edge, of a child process exiting. A blocking call to waitpid() will wait for the condition, the level, of that specific child process no longer existing.

When the process exits, a SIGCHLD will be delivered, and its handler will execute normally. If there was a waitpid() blocking on that process, it will then return as normal, regardless of the presence of a signal handler.

like image 133
LeoNerd Avatar answered Oct 11 '22 10:10

LeoNerd