signal() - specify signal handling (C Standard version)
#include <signal.h>
void (*signal (int sig, void (*func)(int)))(int)
The signal(2) call allows a process to catch, ignore, or to generate an interrupt on receiving a signal. (The exceptions are SIG_KILL and SIG_STOP, which cannot be caught or ignored.) The recommended call instead of signal(2) is the POSIX sigaction(2) call, which is slightly more robust.
The sig is a signal number (possible values are listed below or in the file <signal.h>).
The func argument is either a function to catch and handle the signal or one of these macros:
Signals allow the manipulation of a process from outside its domain as well as allowing the process to manipulate itself or copies of itself (children). There are two general types of signals: those that cause termination of a process and those that do not. Signals which cause termination of a program might result from an irrecoverable error or might be the result of a user at a terminal typing the `interrupt' character. For example, signals are used when a process is stopped to access the process's control terminal while in the background. Signals are optionally generated when a process resumes after being stopped, when the status of child processes changes, or when input is ready at the control terminal. Most signals result in the termination of the process receiving them if no action is taken; some signals instead cause the process receiving them to be stopped, or are simply discarded if the process has not requested otherwise.
For a list of signals defined in the file <signal.h>, see the sigaction(2) reference page.
The handled signal is unblocked with the function returns and the process continues from where it left off when the signal occurred.
When a process which has installed signal handlers forks, the child process inherits the signals. All caught signals may be reset to their default action by a call to the execve(2) function; ignored signals remain ignored.
On success, signal(2) returns the previous action. Otherwise, it returns -1 and sets errno to indicate the error.
The signal(2) call will fail and no action will take place if one of the following occur:
kill(1)
kill(2)
sigaction(2)
sigprocmask(2)
sigsuspend(2)
setjmp(3)