Linux Signals Explained: SIGTERM, SIGKILL and How Processes Really Die


Every Linux user has typed kill -9 at some point, usually in frustration. But -9 is the nuclear option, and most of the time it’s the wrong first move. Linux processes communicate through signals — small messages the kernel delivers to a process — and understanding the handful that matter makes you a calmer, safer sysadmin.

What Is a Signal?

A signal is a notification sent to a process: “stop”, “reload your config”, “shut down”, “you’re out of time”. Signals come from the kernel, from other processes, or from your keyboard — Ctrl+C sends SIGINT, Ctrl+Z sends SIGTSTP. A process can catch a signal and handle it gracefully, ignore it, or be killed by it. The one exception: two signals can neither be caught nor ignored.

The Signals You Actually Need

  • SIGTERM (15) — the polite shutdown request. kill <pid> sends this by default. The process gets a chance to save its work, close files, flush buffers and exit cleanly. Always try this first.
  • SIGKILL (9) — the executioner. The kernel kills the process immediately, no cleanup, no goodbye. The process cannot catch or ignore it. Use it only when SIGTERM fails, because a killed process can leave corrupted files, locked databases and half-written data behind.
  • SIGINT (2) — what Ctrl+C sends. Most programs treat it as “stop what you’re doing and exit”.
  • SIGHUP (1) — sent when a terminal closes. Daemons traditionally treat it as “reload your configuration”, which is why kill -HUP <pid> reloads services like nginx without downtime.
  • SIGSTOP (19) and SIGCONT (18) — freeze and resume a process. SIGSTOP can’t be caught either, which makes it useful for pausing a runaway process before you decide what to do with it.

kill, pkill and killall in Practice

kill 1234 # send SIGTERM to PID 1234 (polite first)
kill -TERM 1234 # same thing, explicit
kill -9 1234 # SIGKILL — only if SIGTERM didn't work
kill -HUP 1234 # ask a daemon to reload its config
pkill -f nginx # SIGTERM every process matching "nginx"
killall firefox # SIGTERM all processes named firefox

Check first with ps aux | grep <name> so you know exactly which PID you’re about to signal. Signalling the wrong process on a server is a mistake you make exactly once.

The Graceful Shutdown Pattern

When a service won’t stop, work the ladder instead of jumping to -9:

kill 1234 # SIGTERM — give it a few seconds
sleep 5
ps -p 1234 # still alive?
kill -9 1234 # only now, as a last resort

Most well-written programs exit within seconds of SIGTERM. If a process ignores it, something is wrong — a stuck disk, a deadlocked thread — and SIGKILL papers over the problem instead of fixing it. Investigate with ps and journalctl before reaching for -9.

Signals and Security

Signals matter for defense too. A process running as root can only be signalled by root (or the same user), which is why privilege separation matters: a compromised web app user can’t SIGKILL your database if it runs as a different user. And when you’re hardening a server, remember that kill -9 on a database can corrupt data — graceful shutdowns are part of availability, not just politeness.

Next time a process misbehaves, start with SIGTERM. Save -9 for when politeness has genuinely failed.

Comments

Popular Posts