Skip to content
Latchkey

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

SignalNumDefault
SIGHUP1Terminate (reload by convention)
SIGINT2Terminate (Ctrl-C)
SIGQUIT3Terminate + core dump
SIGKILL9Terminate (uncatchable)
SIGTERM15Terminate (graceful, default kill)
SIGSTOP / SIGCONT19 / 18Pause / resume

SIGTERM vs SIGKILL

SignalBehavior
SIGTERM (15)Polite ask; process can clean up
SIGKILL (9)Force kill; cannot be caught or ignored
Docker stopSIGTERM, 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"' EXIT

Key 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →