SIGCHLD
Encyclopedia
On POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

-compliant platforms, SIGCHLD is the signal
Signal (computing)
A signal is a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. Essentially it is an asynchronous notification sent to a process in order to notify it of an event that occurred. When a signal is sent to a process, the operating system...

 sent to a process
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

 when a child process terminates
Exit (operating system)
On many computer operating systems, a computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running. The operating system reclaims resources that were used by the process...

. The symbolic constant
C preprocessor
The C preprocessor is the preprocessor for the C and C++ computer programming languages. The preprocessor handles directives for source file inclusion , macro definitions , and conditional inclusion ....

 for SIGCHLD is defined in the header file
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...

 signal.h
Signal.h
signal.h is a header file defined in the C Standard Library to specify how a program handles signals while it executes. A signal can report some exceptional behavior within the program , or a signal can report some asynchronous event outside the program .A signal can be generated...

. Symbolic signal names are used because signal numbers can vary across platforms.

On Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

, SIGCLD is a synonym for SIGCHLD.

Etymology

SIG is a common prefix for signal names. CHLD and CLD are abbreviation
Abbreviation
An abbreviation is a shortened form of a word or phrase. Usually, but not always, it consists of a letter or group of letters taken from the word or phrase...

s for child.

Usage

In Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

, a process can have children
Child process
A child process in computing is a process created by another process .A child process inherits most of its attributes, such as open files, from its parent. In UNIX, a child process is in fact created as a copy of the parent...

 created by fork/vfork
Fork (operating system)
In computing, when a process forks, it creates a copy of itself. More generally, a fork in a multithreading environment means that a thread of execution is duplicated, creating a child thread from the parent thread....

 or similar system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

s . When the child terminates a SIGCHLD signal is sent to the parent
Parent process
In computing, a parent process is a process that has created one or more child processes.- Unix :In the operating system Unix, every process except is created when another process executes the fork system call. The process that invoked fork is the parent process and the newly-created process is...

. By default the signal is simply ignored. However commonly wait system call implemented in a handler for the SIGCHLD, so that the parent may act upon the exit status
Exit status
The exit status or return code of a process in computer programming is a small number passed from a child process to a parent process when it has finished executing a specific procedure or delegated task...

 of the child.

When a child process terminates before the parent has called wait, the kernel retains some information about the process to enable its parent to call wait later . Because the child is still consuming system resources but not executing it is known as a zombie process
Zombie process
On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the process that started the process to read its exit status. The term zombie process...

.

POSIX.1-2001
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 allows a parent process to elect for the kernel to automatically reap child processes that terminate by setting the disposition of SIGCHLD to SIG_IGN or by setting the SA_NOCLDWAIT flag for the SIGCHLD signal; Linux 2.6 kernels adhere to this behavior, and FreeBSD supports both of these methods since version 5.0 . However, because of historical differences between System V and BSD behaviors with regard to ignoring SIGCHLD, calling wait remains the most portable paradigm for cleaning up after forked child processes.

Listed below is code that will elect automatic child reaping, shown in a number of programming languages:
Language Syntax
C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 (classic)
signal(SIGCHLD, SIG_IGN);
C struct sigaction sa = {.sa_handler = SIG_IGN}; sigaction(SIGCHLD, &sa, NULL);
OCaml Sys.set_signal Sys.sigchld Sys.Signal_ignore
Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

fpsignal(SIGCHLD, SIG_IGN);
Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

$SIG{CHLD} = 'IGNORE';
PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

pcntl_signal(SIGCHLD, SIG_IGN);
Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

signal.signal(signal.SIGCHLD, signal.SIG_IGN)
Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

Signal.trap('CHLD', 'IGNORE')
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK