End a process properly
TERM lets the program close files and remove temporary ones. KILL is the last resort.
The kill command sends a signal to a PID — ask it to exit (TERM), reload settings (HUP), or end it at once (KILL).
kill 1234
SIGTERM: ask it to exit
kill -TERM 1234
the same, explicitly (-15)
kill -HUP 1234
reload settings (for many services)
kill -KILL 1234
SIGKILL: end at once, no cleanup (-9)
kill -STOP 1234
pause; -CONT resumes
kill -0 1234
is the process alive (sends nothing)
kill %1
job 1 of this terminal
kill -l
list of signals
pkill -f 'python app.py'
by a command-line pattern
pkill -u student sleep
by name, for one user
kill doesn't necessarily kill: it sends a process a signal. The
process decides what to do with it, except for two — KILL and STOP, which the
kernel carries out.
| Signal | Number | Meaning |
|---|---|---|
TERM |
15 | exit: save data, clean up (the default) |
INT |
2 | interrupt — the same as Ctrl+C |
HUP |
1 | many services reload their settings |
KILL |
9 | the kernel removes the process at once, no cleanup |
STOP / CONT |
19 / 18 | freeze / unfreeze |
Get the process number from ps, top or pgrep:
You can signal only your own processes. Others' — with sudo.
The kill you type is a Bash builtin: it understands %1 (a job number). The
separate program /bin/kill does the same for PIDs. Full list — help kill and man
kill.
| Option | What it does | Example |
|---|---|---|
-TERM |
Ask the process to exit (15, the default signal). | kill -TERM 1234 |
-KILL |
Remove the process at once, without cleanup (9). Only if TERM failed. dangerous | kill -KILL 1234 |
-HUP |
Signal 1 — many services reload their settings on it. | kill -HUP 1234 |
-0 |
Send nothing — just check that the process exists and is reachable. | kill -0 1234 |
-l |
List signal names; -l 9 names a signal by its number. | kill -l |
-STOP |
Freeze the process (19); resume with -CONT. | kill -STOP 1234 |
-s signal |
A signal by name or number — the same as -NAME. | kill -s HUP 1234 |
Nothing found. Try a shorter query.
TERM lets the program close files and remove temporary ones. KILL is the last resort.
pkill matches part of the name: pkill ssh hits sshd too. Check the list with
pgrep -a and the same pattern. killall from the psmisc package matches the exact
name, but a minimal system may not have it.
systemd restarts a service killed with kill if it has Restart= — see
systemctl.
Ctrl+C sends INT, Ctrl+Z sends TSTP (stops it and returns the prompt). After
Ctrl+Z: kill %1 or fg — see background-jobs.
There's no process with that PID anymore: it exited, or the PID was mistyped. Find the
current one: pgrep -a name.
The process belongs to another user or root. Check the owner with ps -o user= -p
PID; if the signal is really needed — sudo kill PID.
State Z (zombie): the process exited, the parent hasn't collected it. It needs no
signals — end or restart the parent (ps -o ppid= -p PID). State D: the process
waits on the disk; the signal takes effect after the I/O.
systemd or another supervisor restarts it. Check systemctl status PID and stop the
service: sudo systemctl stop name.
There's no such signal — usually a typo in the name. Use -TERM, -HUP, -KILL or
the number -15; kill -l prints the full list.
kill -9 as the first moveKILL gives the program no chance to save data: a database may be left with an unfinished write, and the program may leave lock and temporary files that stop it from starting again. Use TERM and a few seconds of waiting first.
pkill -f python run with sudo ends every Python program on the machine. kill -9
-1 sends KILL to all your processes, including the shell — the session drops. Before
pkill, always run pgrep -a with the same pattern.
pkill with the same conditions.k in top sends a signal.jobs, fg, kill %1.Found an inaccuracy? Report an error in the article