What a signal is
A signal is a one-word message the kernel delivers to a process: “the terminal closed”, “you touched bad memory”, “please stop”. The process may install a handler for most of them, ignore them, or accept the default action, which is usually to terminate (sometimes with a core dump). Two cannot be caught or ignored: SIGKILL ends the process on the spot and SIGSTOP freezes it.
TERM versus KILL
kill PID sends SIGTERM: a request. A well-written program catches it, finishes the current request, flushes files, closes connections and exits; that is what systemd, Docker and Kubernetes send first. kill -9 sends SIGKILL: the kernel removes the process without running any of its code, so locks stay held, temp files stay, and in-flight writes are lost. Use it only after TERM has been given time (systemd waits TimeoutStopSec, Docker 10 seconds by default) and failed.
Signals as an API
- SIGHUP: daemons reload their configuration (nginx, sshd, HAProxy with
-sfsemantics via systemd reload). For a foreground process it means the terminal went away;nohupignores it. - SIGUSR1 / SIGUSR2: program-defined. nginx reopens logs on USR1 and upgrades its binary on USR2;
ddprints progress on USR1; Gunicorn and Unicorn use them for graceful restarts. - SIGPIPE: writing to a pipe whose reader has exited. Its default action, terminating, is why
yes | headends and why servers must ignore it or handle write errors. - SIGCHLD: a child exited; parents reap children with
wait(), and a parent that does not leaves zombies. - SIGWINCH: the terminal was resized; editors and multiplexers redraw.
Sending signals
kill -TERM 1234 # by name (or kill -15 1234)
kill -s USR1 $(pidof nginx)
pkill -HUP sshd # by process name
killall -9 runaway # all processes with that name
systemctl kill -s HUP myservice
docker kill --signal=SIGUSR1 container Numbers 1–15 are the same on every Unix; above that they differ by architecture (SIGUSR1 is 10 on x86 and 30 on SPARC/MIPS), which is why scripts should use names.
Questions
What is the difference between SIGTERM and SIGKILL?
SIGTERM asks the process to exit and can be handled; SIGKILL ends it immediately and cannot be caught. Always try TERM first; KILL is for processes that are stuck.
What is signal 11 / SIGSEGV?
A segmentation fault: the program read or wrote memory it does not own, usually a null or dangling pointer in C/C++ code or a bug in a native extension. The shell reports exit code 139.
Why did my process exit with 137 when nobody ran kill -9?
The kernel did: the out-of-memory killer sends SIGKILL to the largest process when memory runs out, and container runtimes do the same when a memory limit is hit. Check dmesg or the container’s OOMKilled flag.
Can I ignore SIGINT so Ctrl-C does not stop my script?
Yes: trap "" INT in bash, or signal.signal(SIGINT, SIG_IGN) in Python. Usually it is better to trap it and clean up before exiting, so the user can still stop the script.