A signal is a software interrupt: a standardised, numbered message delivered asynchronously to a process. Signals are how Unix systems communicate events like "your child exited" (SIGCHLD), "the user pressed Ctrl+C" (SIGINT), "please terminate cleanly" (SIGTERM), "die now" (SIGKILL), "segmentation fault" (SIGSEGV), and "hang up" (SIGHUP). About 30 standard signals are defined, plus a range of real-time signals.
A process can install a handler for most signals, choose to ignore them, or let the default action happen (which is usually to terminate the process). Two signals cannot be caught, blocked, or ignored: SIGKILL (#9) and SIGSTOP (#19). They always take effect, which is why kill -9 is the hammer of last resort.
kill <PID> # default: SIGTERM
kill -9 <PID> # SIGKILL
kill -HUP <PID> # reload config (daemons' convention)
kill -l # list signal names and numbers
pkill -HUP nginx # signal by name
Well-behaved daemons treat SIGTERM as "finish current work and exit cleanly" and SIGHUP as "reload your configuration without restarting". SIGKILL should be reserved for processes that refuse to die; it gives them no chance to clean up.
Discussed in:
- Chapter 10: Processes and Job Control · Signals
Also defined in: Textbook of Linux
