Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SIGCHLD dispatched on SIGTERM?

Tags:

linux

signals

The Wikipedia page for SIGCHLD says:

The SIGCHLD signal is sent to the parent of a child process when it exits, is interrupted, or resumes after being interrupted.

Does that mean that when the parent process sends any signal (such as SIGTERM) to the child process, it will in turn receive a SIGCHLD back from the child?

Or do I misinterpret interrupt (I assume it to mean any signal received), in this case, which signals are concerned?

like image 533
BenMorel Avatar asked Aug 26 '13 10:08

BenMorel


People also ask

Can a process ignore SIGTERM?

The SIGTERM signal is a generic signal used to cause program termination. Unlike SIGKILL , this signal can be blocked, handled, and ignored.

What is the SIGCHLD signal?

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

Does Waitpid use SIGCHLD?

Define a handler for SIGCHLD that calls waitpid This allows for the possibility of SIGCHLD being raised for reasons other than the termination of a child process. ( SIGCHLD has three conventional uses: to indicate that a child process has terminated, stopped or continued.

What is the default action of SIGCHLD?

Note that the default action for SIGCHLD is to ignore this signal; nevertheless signal(SIGCHLD, SIG_IGN) has effect, namely that of preventing the transformation of children into zombies.


1 Answers

A SIGCHLD is delivered to the parent in these cases:

  • The child process exits.
  • The child process is stopped by a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal
  • The child process is resumed by a SIGCONT signal

I would presume the SIGSTOP/SIGCONT is what wikipedia means by "interrupted".

The default handler for SIGTERM is to terminate the process. So if the parent sends SIGTERM to the child process which terminates that child, then yes - the parent will receive a SIGCHLD.

If the child installs a signal handler that does not terminate it, there will be no SIGCHLD signal delivered to the parent.

like image 197
nos Avatar answered Sep 21 '22 20:09

nos