SIGCHLD Signal Processing

darksky picture darksky · Mar 23, 2012 · Viewed 22.9k times · Source

In Unix, when a child process in background terminates, it sends a SIGCHLD signal to the parent to inform it that it terminated.

Does the same happen even if the process was in foreground? If so, this means the parent will just ignore it.

Is this right? Or if it is in foreground, then no signal is sent at all?

Answer

jim mcnamara picture jim mcnamara · Mar 23, 2012

background and foreground are job control concepts, and are part of the the shell. They are applied to processes and do not affect which process spawned (exec-ed) another process.

A child process is the result of a fork()-exec() call. The child gets a parent pid of the process that executed the fork() call. This is the context of the SIGCHLD signal, the parent pid receives the SIGCHLD signal. It does not matter whether the child process is "foreground" or "background", only the ppid matters on exit of the process.