kill
Send a signal to a process — terminate it gracefully, kill it, reload its config, pause it
kill doesn't necessarily kill — it sends a signal to a process by PID. What happens next is up to the process: most signals can be caught or ignored. By default TERM is sent — a request to exit.
Syntax
kill [-signal] PID…
kill -s signal PID…
kill -l [number]
The signal can be given by name with or without the SIG prefix, or by number: kill -TERM, kill -SIGTERM, kill -15, kill -s TERM are all the same.
Options
| Option | What it does |
|---|---|
-SIGNAL / -N | which signal to send (default TERM) |
-s SIGNAL | the same, as a separate argument |
-l | list of signals; kill -l 15 → TERM, kill -l 137 → KILL (translates the 128+N code) |
-L | a table of signals (/bin/kill only) |
-0 | send nothing, just check: the process exists and you're allowed to signal it |
%1 | instead of a PID — a shell job number (jobs) |
-- -PGID | a negative number — signal the whole process group |
kill is usually a bash builtin; there's also a standalone program /bin/kill from procps with the same main options.
Signals
| Signal | # | Default action | When it's used |
|---|---|---|---|
HUP | 1 | terminate | the terminal closed; many daemons (nginx, sshd) reload their config on HUP |
INT | 2 | terminate | what Ctrl+C sends |
QUIT | 3 | terminate with a core dump | Ctrl+\ |
KILL | 9 | kill immediately | the last resort: can't be caught or ignored |
USR1 / USR2 | 10 / 12 | terminate | up to the program: reopen logs, print statistics |
PIPE | 13 | terminate | writing to a closed pipe (yes | head) |
TERM | 15 | terminate | a polite request to exit, the default signal; the program can clean up |
CHLD | 17 | ignore | a child process exited |
CONT | 18 | continue | resume a stopped process |
STOP | 19 | stop | freeze a process; can't be caught |
TSTP | 20 | stop | Ctrl+Z; unlike STOP, can be caught |
The numbers are for Linux on x86_64 and ARM; some differ on other architectures, so names are more reliable in scripts. A process killed by signal N exits with code 128+N: TERM → 143, KILL → 137, INT → 130.
Examples
# politely terminate a process
kill 1234
# if that didn't help after a few seconds — kill it
kill -9 1234
# reload a daemon's configuration without restarting it
kill -HUP "$(cat /run/nginx.pid)"
# pause and resume
kill -STOP 1234
kill -CONT 1234
# is the process alive (sends nothing)
if kill -0 1234 2>/dev/null; then echo "running"; fi
# which signal is behind code 137
kill -l 137 # KILL
# a shell background job
sleep 100 &
kill %1
# PID of the last background process and its code after it exits
sleep 100 & pid=$!
kill "$pid"; wait "$pid"; echo $? # 143
# the whole process group (e.g. a script and its children)
kill -TERM -- -4321
Pitfalls
- Don't start with
-9.KILLdoesn't let the process close files, delete its PID file and locks, or flush buffers.TERMfirst, wait, and only thenKILL. killkills only the given process, not its children. The children are orphaned and reparented to PID 1. To hit all of them, signal the group:kill -- -PGID.- A process in state
Ddoesn't react even toKILLuntil it returns from the kernel (usually it's waiting on a disk or NFS). A zombie (Z) can't be killed at all — it has already exited. - A process can ignore a signal.
trap '' TERMin a script, andkilldoes nothing. To see the mask of ignored signals: theSigIgnline in/proc/<pid>/status. - Background processes started from a script ignore
INTandQUIT(bash does this when job control is off). Send themTERM. - A PID can change owners. Between
psandkillthe process may have exited and its number gone to another one. Kill by a fresh PID or viapkillwith an exact pattern. kill -0also returns an error for someone else's process if you lack permissions — that doesn't mean the process doesn't exist.killallisn't installed in the image; to kill by name usepkill.
See also
pgrep · ps · exit-codes · service