C signal handling

In the C Standard Library, signal processing defines how a program handles various signals while it executes. A signal can report some exceptional behavior within the program (such as division by zero), or a signal can report some asynchronous event outside the program (such as someone striking an interactive attention key on a keyboard).

Standard signals
The C standard defines only 6 signals. They are all defined in  header (  header in C++):


 * – "abort", abnormal termination.
 * – floating point exception.
 * – "illegal", invalid instruction.
 * – "interrupt", interactive attention request sent to the program.
 * – "segmentation violation", invalid memory access.
 * – "terminate", termination request sent to the program.

Additional signals may be specified in the  header by the implementation. For example, Unix and Unix-like operating systems (such as Linux) define more than 15 additional signals; see Unix signal.

Debugging

 * for debugging purposes. It's platform-dependent and may be used on Unix-like operating systems.

Handling
A signal can be generated by calling  or   system calls. sends a signal to the current process,  sends a signal to a specific process.

A signal handler is a function which is called by the target environment when the corresponding signal occurs. The target environment suspends execution of the program until the signal handler returns or calls.

Signal handlers can be set with  or. The behavior of  has been changed multiple times across history and its use is discouraged. It is only portable when used to set a signal's disposition to SIG_DFL or SIG_IGN. Signal handlers can be specified for all but two signals (SIGKILL and SIGSTOP cannot be caught, blocked or ignored).

If the signal reports an error within the program (and the signal is not asynchronous), the signal handler can terminate by calling,  , or.