UNIX Signals
SIGINT, SIGTERM, SIGKILL, SIGQUIT, SIGABRT... it seems like UNIX has a confusing number of signals that terminate a process. Here’s a list to help sort them out.
Name | Number | Meaning | Default action | Key |
---|---|---|---|---|
INT |
2 |
Terminal interrupt — this is specifically the user asking for the program’s attention. Sent to all processes in the foreground process group for this terminal. |
Terminate process | ^C | HUP |
1 |
Terminal line hang up (or process group orphaned or controlling process exited) |
Terminate process |
TERM |
15 |
Terminate — this is the "normal" termination signal sent by |
Terminate process | |
QUIT |
3 |
Abnormal program termination from terminal. Sent to all processes in the foreground process group for this terminal. |
Dump core | ^\ |
ABRT |
6 |
Abnormal program termination — used by |
Dump core | |
KILL |
9 |
Kill program (cannot be caught or ignored) — used by system to kill processes: Note: |
Terminate process | |
STOP |
17 |
Stop (cannot be caught or ignored) |
Stop (suspend) process | |
TSTP |
18 |
Stop signal generated from terminal |
Stop (suspend) process | ^Z |
INFO |
19 |
Status request from terminal |
Discard signal | ^T |
NOTE: Signal numbers 17, 18, and 19 are not standardized by POSIX. The SIGINFO
signal is not standardized by POSIX.
Overview
To recap, there are basically three types of program terminate signals:
TERM
— the "please exit" signalABRT
— the "abnormal termination" signalKILL
— the "you must die" uncatchable signal
QUIT
is the terminal-generated ABRT
equivalent.
INT
is not a termination signal necessarily, but if the program doesn’t have any better action to take, the default is termination.
HUP
is also not a termination signal necessarily, but if the program doesn’t have any better action to take, the default is termination.
STOP
and TSTP
, though their name may sound like termination, are really job control signals used to suspend a process for later resumption (in the foreground or background).
INFO
is a non-standard, but common, signal that by default prints a one-line status of the current command and processor usage. [Don't confuse the INFO
signal (19) with the SA_SIGINFO
flag or the siginfo_t
type in signal.h
.]
Your Program Should...
On SIGINT
, SIGHUP
, or SIGTERM
: Clean up temporary files as it exits.
On SIGQUIT
and SIGABRT
: "Bypass any recovery actions", and dump state.
On SIGKILL
: Nothing, since it can't be caught. Just leave a mess. :-)
For Java programs, the JVM shutdown hook mechanism is invoked on SIGINT
, SIGHUP
, or SIGTERM
, but not SIGQUIT
or SIGABRT
.