The header <signal.h> declares a type and two functions and defines several macros for handling various signals (conditions that may be reported during program execution).
The type defined is
which is the integral type of an object that can be access as an atomic entity, even in the presence of asynchronous interrupts.
The macros defined are:
which expand to constant expressions with distinct values that are type compatible with the second argument to and the return value of the signal function, and whose value compares unequal to the address of any declarable function; and the following, each of which expands to a positive integral constant expression that is the signal number corresponding to the specified condition.
SIGHUP Hangup (POSIX).
SIGINT Interrupt (ANSI).
SIGQUIT Quit (POSIX).
SIGILL Illegal instruction (ANSI).
SIGABRT Abort (ANSI).
SIGTRAP Trace trap (POSIX).
SIGIOT IOT trap (4.2 BSD).
SIGEMT EMT trap (4.2 BSD).
SIGFPE Floating-point exception (ANSI).
SIGKILL Kill, unblock-able (POSIX).
SIGBUS Bus error (4.2 BSD).
SIGSEGV Segmentation violation (ANSI).
SIGSYS Bad argument to system call (4.2 BSD)
SIGPIPE Broken pipe (POSIX).
SIGALRM Alarm clock (POSIX).
SIGTerm Termination (ANSI).
SIGUSR1 User-defined signal 1 (POSIX).
SIGUSR2 User-defined signal 2 (POSIX).
SIGCHLD Child status has changed (POSIX).
SIGCLD Same as SIGCHLD (System V).
SIGPWR Power failure restart (System V).
(*signal (int sig, void
(*func)(int))) signal (
The signal function chooses one of three ways in which receipt of the signal number sig is to subsequently handled. If the value of func is SIG_DFL, default handling for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored. Otherwise func shall point to a function to be called when the signal occurs. Such a function is called a signal handler.
When a signal occurs, if func points to a function, first the equivalent of signal(SIG,SIG_DFL); is executed or an implementation-defined blocking of the signal is performed. (If the value of the signal is SIG_KILL, whether the reset to SIG_DFL occurs is implementation defined.) Next the equivalent of (*func)(sig); is executed. The function func may terminate by executing a return statement of by calling the abort, exit or longjmp function. If func executes a return statement, and the value of sig was SIGFPE or any other implementation-defined value corresponding to a computational exception, the behavior is undefined. Otherwise, the program will resume execution at the point it was interrupted.
If the signal occurs other than as the result of calling the abort or raise function, the behavior is undefined if the signal handler calls any function in the standard library other than the signal function itself (with a first argument of the signal number corresponding to the signal that cause the invocation of the handler) or refers to any object with status storage duration other than by assigning to a static storage duration variable of type volatile sig_atomic_t. Furthermore, if such a call to the signal function results in a SIG_ERR return, the value of errno is indeterminate.
At program startup, the equivalent of signal(sig, SIG_IGN); is executed for some signal selected in an implementation-defined manner, the equivalent of signal(sig, SIG_DFL); is executed for all other signals defined by the implementation.
The implementation shall behave as if no library function calls the signal function.
If the request can be honored, the signal function returns the value of func for the most recent call to signal for the specified signal sig. Otherwise a value of SIG_ERR is returned and a positive value is stored in errno.