kill
Overview
kill sends a signal to one or more processes by PID. Despite the name, the default signal is TERM (15) — a polite request to exit. Only escalate to KILL (9) after a graceful stop fails. Prefer systemctl stop / systemctl reload for units managed by systemd.
Syntax
kill [options] PID...
kill -SIGNAL PID...
kill -s SIGNAL PID...
kill -l [signal]Common Options
| Option | Description |
|---|---|
-s SIGNAL, -SIGNAL |
Signal name or number (TERM, HUP, 9, …) |
-l |
List signal names (or translate a number ↔︎ name) |
-n SIGNAL |
Same idea as -s on some implementations |
-p (bash builtin only) |
Print PID instead of signaling (shell-specific) |
Signals you will use constantly:
| Signal | Number | Typical meaning |
|---|---|---|
TERM |
15 | Graceful stop (default) |
HUP |
1 | Hangup / often “reload config” |
INT |
2 | Interrupt (like Ctrl-C) |
QUIT |
3 | Quit with core (if allowed) |
KILL |
9 | Force kill — uncatchable |
STOP |
19 | Pause (uncatchable) |
CONT |
18 | Resume after STOP |
USR1 / USR2 |
10 / 12 | Application-defined |
Safety
- Always verify the PID before signaling:
ps -p PID -o pid,user,cmdorps -fp PID. - TERM first, then wait, then KILL — never jump to
-9on production workers unless the process is wedged. - Wrong PID on a multi-tenant host can take down databases, SSH, or the wrong customer job.
- You may only signal processes you own unless you are root.
- Prefer service managers for supervised daemons:
systemctl stop UNIT, not ad-hockillon random PIDs fromps.
Key Use Cases
- Stop a runaway user process after verifying the PID
- Reload a daemon that documents
SIGHUPhandling - Force-kill a process stuck in userspace after TERM fails
- Test whether a PID still exists (
kill -0)
Examples with Explanations
Example: graceful stop (default TERM)
ps -fp 1234
kill 1234
# same as:
kill -TERM 1234
kill -15 1234
kill -s TERM 1234Default signal is TERM. Confirm the process is the one you intend with ps first.
Example: TERM, wait, then KILL
PID=1234
kill -TERM "$PID"
for i in 1 2 3 4 5; do
kill -0 "$PID" 2>/dev/null || break
sleep 1
done
if kill -0 "$PID" 2>/dev/null; then
echo "still alive; forcing" >&2
kill -KILL "$PID"
fikill -0 PID checks existence and permission without delivering a real signal. Use this pattern instead of blind kill -9.
Example: force kill only when necessary
kill -KILL 1234
# or
kill -9 1234KILL cannot be caught or cleaned up. File locks, temp files, and child reaping may be messy. Prefer TERM whenever the process still responds.
Example: reload via HUP
kill -HUP "$(pidof nginx)"
# better for packaged services:
sudo systemctl reload nginxMany classic daemons reload config on HUP. Prefer systemctl reload so systemd tracks state and uses the unit’s configured reload command.
Example: signal by name via pgrep
kill $(pgrep -x myapp)
# often clearer:
pkill -x myapp
pkill -TERM -x myappShell word-splitting on $(pgrep …) is fine for PIDs; still prefer exact match (-x) so you do not hit similarly named processes.
Example: stop / continue (debug freeze)
kill -STOP 1234 # freeze
# inspect, attach debugger, etc.
kill -CONT 1234 # resumeSTOP/CONT are useful for debugging or temporarily freezing a CPU hog. A STOP’d process will not exit until CONT (or KILL).
Example: list signals
kill -l
kill -l 15 # → TERM (often)
kill -l TERM # → 15Handy when docs show only numbers or only names.
Example: multiple PIDs
kill -TERM 1001 1002 1003
kill -TERM $(pgrep -u "$USER" -f 'worker.py')One invocation can target many PIDs. Combine with careful pgrep filters (-u, -f, -x).
Example: permission check without killing
if kill -0 1234 2>/dev/null; then
echo "process exists and is signalable"
else
echo "gone or not permitted"
fiExit status of kill -0 is ideal for scripts that poll for death after TERM.
Understanding Output
- Success is silent; failures print to stderr (
No such process,Operation not permitted). - Exit status non-zero if any PID failed (implementation details vary slightly for multi-PID).
- Bash has a
killbuiltin that may differ slightly from/bin/kill(util-linux); both understand standard signals.
Notes & Pitfalls
- Zombies (
Zstate) ignore signals; kill the parent or fix whatever is notwait()ing. - Processes in uninterruptible sleep (
Dstate, often I/O) may not die until the wait ends — KILL does not magically fix stuck NFS or bad block devices. - Killing PID 1 is a terrible idea; on systemd hosts it will refuse nonsense, but do not experiment.
- Job-control shells also understand
%1job specs with the builtinkill— different from numeric PIDs. - Containers: killing PID 1 inside a container usually stops the container; know your runtime’s restart policy.
Additional Resources
man 1 killman 7 signal