SIGCHLD

From Wikipedia, the free encyclopedia

SIGCHLD
Description: Child process terminated or stopped
Default action: Ignore the signal
SA_SIGINFO macros
CLD_EXITED child has exited
CLD_KILLED child has terminated abnormally and did not create a core file
CLD_DUMPED child has terminated abnormally and created a core file
CLD_TRAPPED traced child has trapped
CLD_STOPPED child has stopped
CLD_CONTINUED stopped child has continued

On POSIX-compliant platforms, SIGCHLD is the signal thrown by computer programs when a child process terminates. The symbolic constant for SIGCHLD is defined in the header file signal.h. Symbolic signal names are used because signal numbers can vary across platforms.

On Linux, SIGCLD is a synonym for SIGCHLD.

Contents

[edit] Etymology

SIG is a common prefix for signal names. CHLD and CLD are abbreviations for child.

[edit] Usage

In Unix, a process can have children, created by fork or similar system calls. The parent, if available, is notified of the termination of a child process via a SIGCHLD signal. The parent does not need to register for it via the signal system call since it gets this signal by default. This signal can be ignored by the parent if needed.

[edit] Zombie processes

Ignoring the SIGCHLD signal will create "zombies": The operating system will keep status information about the terminated child (in particular, the return code) until the parent executes the wait() system call to receive this information.

In some situations this might be acceptable: Zombies use only few system resources and disappear when their parent process terminates. But careful programmers will always have programs wait for their children. In general, a program should use a SIGCHLD signal handler that executes wait in order to avoid zombies.

In Perl, setting $SIG{'CHLD'}="IGNORE" will, in fact, install such a signal handler. In Python, signal.signal(signal.SIGCHLD, signal.SIG_IGN) will do the same.

[edit] External links


POSIX Signals
SIGABRT | SIGALRM | SIGFPE | SIGHUP | SIGILL | SIGINT | SIGKILL | SIGPIPE | SIGQUIT | SIGSEGV | SIGTERM | SIGUSR1 | SIGUSR2 | SIGCHLD | SIGCONT | SIGSTOP | SIGTSTP | SIGTTIN | SIGTTOU | SIGBUS | SIGPOLL | SIGPROF | SIGSYS | SIGTRAP | SIGURG | SIGVTALRM | SIGXCPU | SIGXFSZ | Realtime Signals are user definable—SIGRTMIN+n through SIGRTMAX.
Common non-POSIX signals and synonyms
SIGIOT | SIGEMT | SIGSTKFLT | SIGIO | SIGCLD | SIGINFO | SIGPWR (SIGINFO) | SIGLOST | SIGWINCH | SIGUNUSED