Register a signal handler (callback) for the given signal. See remarks below.
Syntax
#include <signal.h>
int signal (int sig, void (*handler)(int));
Parameters
-
sig
The signal to register. It may be one of:
- SIGABRT
- SIGALRM
- SIGBUS
- SIGCHLD
- SIGCONT
- SIGFPE
- SIGHUP
- SIGILL
- SIGINT
- SIGKILL
- SIGPIPE
- SIGQUIT
- SIGSEGV
- SIGSTOP
- SIGTERM
- SIGTSTP
- SIGTTIN
- SIGTTOU
- SIGUSR1
- SIGUSR2
- SIGPOLL
- SIGPROF
- SIGSYS
- SIGTRAP
- SIGURG
- SIGVTALRM
- SIGXCPU
- SIGXFSZ
-
handler
The handler that will be called to handle the signal. If null or
SIG_IGN
, the signal will be unregistered.
Return Value
The return value is always null.
Remarks
Implementation detail: If a program wants to register more than one signal, all signals must be handled by one handler function. The type of signal may be differentiated by the argument supplied to the handler. This constraint is due to memory saving within the kernel.
The signal SIGKILL
can not be caught, it is always fatal. Instead, consider
using SIGINT
which may be caught and handled.
Most signals have no default action, except for the following:
-
SIGCHLD
A child process has terminated.
-
SIGCONT
Continue executing the process.
-
SIGINT
Interrupt, usually due to the user pressing
Ctrl+C
. -
SIGKILL
Terminate the process.
-
SIGTSTP
Stop executing the process. May be triggered by pressing
Ctrl+Z
on the keyboard.