Unix Signals Cheat Sheet: SIGTERM, SIGKILL & Handlers
Unix signals, their numbers, and how to trap them for graceful shutdown.
The signals that stop processes and containers - and how to handle them.
Common signals
| Signal | Num | Default |
|---|---|---|
| SIGHUP | 1 | Terminate (reload by convention) |
| SIGINT | 2 | Terminate (Ctrl-C) |
| SIGQUIT | 3 | Terminate + core dump |
| SIGKILL | 9 | Terminate (uncatchable) |
| SIGTERM | 15 | Terminate (graceful, default kill) |
| SIGSTOP / SIGCONT | 19 / 18 | Pause / resume |
SIGTERM vs SIGKILL
| Signal | Behavior |
|---|---|
| SIGTERM (15) | Polite ask; process can clean up |
| SIGKILL (9) | Force kill; cannot be caught or ignored |
| Docker stop | SIGTERM, then SIGKILL after grace |
Sending & trapping
Terminal
kill -TERM <pid> # or kill <pid>
kill -9 <pid> # SIGKILL
trap 'cleanup; exit 0' TERM INT
trap 'rm -f "$tmp"' EXITKey takeaways
- SIGTERM is catchable for graceful shutdown; SIGKILL is not.
- docker stop sends SIGTERM, then SIGKILL after the grace period.
- trap ... EXIT runs cleanup on any exit path.
Related guides
Exit Codes Cheat Sheet: Shell Status Codes ExplainedAn exit codes cheat sheet - what 0, 1, 2, 126, 127, 130, and signal-derived codes mean, and how to read $? in…
Bash Scripting Cheat Sheet: Variables, Tests & LoopsA bash scripting cheat sheet - variables, parameter expansion, test conditions, loops, functions, and strict-…
Docker CLI Cheat Sheet: Every Command You Use DailyA Docker CLI cheat sheet - run, build, ps, exec, logs, images, volumes, networks, and the prune commands for…