#include <signal.h> void ( *signal( int signal, void (* func) (int)) ) (int);
The signal() function sets func to be called when signal is recieved by your program. func can be a custom signal handler, or one of these macros (defined in signal.h):
| Macro | Explanation |
|---|---|
| SIG_DFL | default signal handling |
| SIG_IGN | ignore the signal |
Some basic signals that you can attach a signal handler to are:
| Signal | Description |
|---|---|
| SIGTERM | Generic stop signal that can be caught. |
| SIGINT | Interrupt program, normally ctrl-c. |
| SIGQUIT | Interrupt program, similar to SIGINT. |
| SIGKILL | Stops the program. Cannot be caught. |
| SIGHUP | Reports a disconnected terminal. |
The return value of signal() is the address of the previously defined function for this signal, or SIG_ERR is there is an error.