Kill vs term vs int vs quit signals

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-11-21

The default behavior of SIGINT, SIGTERM, SIGQUIT and SIGHUP, SIGKILL is to kill the program. However applications are allowed to install a handler for these signals.

In a sense, signals other than KILL exist to give processes a chance to react to the signal.

Specifics

The INT (interrupt) signal is the weakest. It is the signal number 2. Its meaning is "stop what you're doing right now and wait for further user input". It's the signal generated by Ctrl+C in a terminal

The TERM (terminate) signal is the default kill signal (i.e. the one sent when you just call kill). It is signal number 15. It tells the application to exit cleanly. This signal allows for a trap handler, which enables the receiving process to do some clean up in an orderly fashion. An application that doesn't want to be interrupted during a critical operation might ignore SIGTERM for a while.

The HUP signal (hang up) is about the same as SIGTERM in terms of harshness, but it has a specific role because it's automatically sent to applications running in a terminal when the user disconnects from that terminal. It is signal number 1.

The QUIT signal is the harshest of the ignorable signals. It's meant to be used when an application is misbehaving and needs to be killed now, and by default it traditionally left a core dump file. It is signal number 3.

The KILL signal does not have ANY possibility of being resisted. It always works because a KILL signal cannot be handled with a trap. This is both its blessing and its curse. It is signal number 9.

List all signals

$ kill -l
HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH INFO USR1 USR2

Timeouts

Resources