Signals and kill
Updated November 1, 2026
kill sends a process a signal by its PID. A signal is a short message from the kernel.
kill 1234 # TERM (15): exit politely
kill -9 1234 # KILL (9): remove at once, cannot be caught
kill -HUP 1234 # HUP (1): often means reload the config
pkill -x sleep # by name, not PIDSample output
$ cat catcher.sh
trap "echo caught TERM, cleaning up; exit 0" TERM
while :; do :; done
$ bash catcher.sh &
[1] 21
$ kill -9 %1
$ jobs
[1]+ Killed bash catcher.sh
$ bash catcher.sh &
[1] 25
$ kill %1
caught TERM, cleaning upHow it works: why not always -9
A process can catch
TERMand exit cleanly: close files, flush buffers.KILL(-9) cannot be caught, the kernel removes the process at once, and unwritten data is lost. So-9is a last resort.
Common mistakes
A signal number needs the dash. The shell reads kill 9 12345 as "send TERM to processes 9 and 12345" and answers with two lines: bash: kill: (9) - No such process and bash: kill: (12345) - No such process. The right form is kill -9 12345. Another process owner gives a similar surprise: kill on someone else's PID prints bash: kill: (15) - Operation not permitted.
kill %1 and kill $! hit different targets. %1 is the whole job, that is a process group: a script that started sleep 500 & inside goes down together with its child. kill $! signals only the script itself, and after it exits pgrep -a sleep still lists 20 sleep 500 - the orphaned child keeps running.
A zombie cannot be killed by anything. A process in state Z is already dead, only its table entry is left so the exit code can be read, and kill -9 on it passes with no error and no effect: ps -o pid,ppid,stat,comm prints the same line 9 7 Z python3 before and after. The parent clears a zombie when it calls wait; if the parent is stuck, remove the parent and init will collect the entry.
Used in
You need this in the lesson Processes and jobs.