J^T: John Thywissen's personal pages

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
SIGINT
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
SIGHUP
1

Terminal line hang up (or process group orphaned or controlling process exited)

Terminate process
TERM
SIGTERM
15

Terminate — this is the "normal" termination signal sent by kill and shutdown

Terminate process
QUIT
SIGQUIT
3

Abnormal program termination from terminal. Sent to all processes in the foreground process group for this terminal.

Dump core ^\
ABRT
SIGABRT
6

Abnormal program termination — used by abort and assert functions

Dump core
KILL
SIGKILL
9

Kill program (cannot be caught or ignored) — used by system to kill processes: shutdown timeout after SIGTERM or traced process's parent exit or ptrace kill action or code signing failure

Note: SIGKILL bypasses all cleanup / atexit actions. Using it may result in a damaged state.

Terminate process
STOP
SIGSTOP
17

Stop (cannot be caught or ignored)

Stop (suspend) process
TSTP
SIGTSTP
18

Stop signal generated from terminal

Stop (suspend) process ^Z
INFO
SIGINFO
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:

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.