Signal
A signal is an asynchronous notification sent to a process by the kernel, another process, or the user. A process can handle it with custom code, ignore it, or accept the default action, which is often termination.
Understanding Linux Signals
What Is a Signal in Linux?
Signals tell a process something happened without sending data: shut down, reload config, pause. Pressing Ctrl+C sends SIGINT, kill 1234 sends SIGTERM, and systemctl reload triggers a reload that, for services like nginx, is implemented by sending SIGHUP. Graceful shutdowns and zero-downtime reloads depend on them.
How Signal Delivery Works
The kernel marks the signal as pending for the target process. When that process next runs, the kernel checks pending signals and either runs the process's handler or applies the default action.
The Most Important Signals
Numbers below are for common architectures such as x86 and ARM. A few differ on other architectures, so use names in scripts and check kill -l if unsure.
SIGHUP 1 Reload config (terminal hang-up originally)SIGINT 2 Interrupt, Ctrl+C. Can be caughtSIGKILL 9 Immediate kill. Cannot be caught, blocked, or ignoredSIGUSR1 10 Application-defined; some daemons use it to reopen logsSIGUSR2 12 Application-definedSIGTERM 15 Polite terminate. Default of kill. Can be caughtSIGCHLD 17 A child changed stateSIGCONT 18 Resume a stopped processSIGSTOP 19 Pause. Cannot be caught or ignoredWhy SIGTERM Comes Before SIGKILL
SIGTERM lets a process finish in-flight requests, close database connections, flush buffers, and remove lock files. SIGKILL gives it none of that, which can leave locks behind and drop requests. A sound shutdown sequence is: send SIGTERM, wait (for example 30 seconds), then SIGKILL only if it is still running. Kubernetes follows this pattern with its termination grace period.
Practical Signal Commands
kill 1234 # SIGTERMkill -HUP 1234 # reloadkill -9 1234 # last resortkill -0 1234 # test existence and permission, sends nothingkill -l # list signals pkill -f 'python3 worker.py'killall nginx # Handle signals in a scripttmpfile=$(mktemp)trap 'rm -f "$tmpfile"' EXITtrap 'echo "SIGTERM caught"; exit 0' TERMTroubleshooting Signals
| Symptom | Command | What to Look For |
|---|---|---|
| kill has no effect | ps -o stat= -p PID |
D state, waiting on I/O |
| Reload does nothing | Check app docs | No SIGHUP handler |
| Ignores SIGTERM | Escalate after timeout | Handler swallows it |
| Zombies | ps -eo stat,pid,ppid |
Parent not reaping |
Tip
kill -0 PIDis the safest liveness check. Exit code 0 means the process exists and you may signal it.
Common MistakeIn containers, running a shell-form
CMDso the shell becomes PID 1 and swallows SIGTERM. Use exec form orexec appin the entrypoint so the app receives it.
SecurityProcesses of the same user can signal each other, and root can signal anything. Dedicated service accounts limit what a compromised service can disturb.
Frequently Asked Questions
What is the practical difference between SIGTERM and SIGKILL?
SIGTERM can be caught, so the app can shut down gracefully. SIGKILL is enforced by the kernel and cannot be caught, so there is no cleanup. Always try SIGTERM first.
Why does my container ignore docker stop?
If the app runs as PID 1 without a SIGTERM handler, or a shell wrapper sits in front of it, the signal is never acted on and Docker sends SIGKILL after the timeout. Use an init such as tini or `docker run --init`, and exec form commands.
How do I reload a service without restarting it?
If the service implements it, `systemctl reload name` or `kill -HUP PID` makes it re-read its config without dropping connections. Not every program handles SIGHUP.