Where to start First steps track · 15 stages
Linux Labs

kill — send a signal to a process

6 min Ubuntu 24.04 · Bash 5.2 · procps-ng 4.0.4

The kill command sends a signal to a PID — ask it to exit (TERM), reload settings (HUP), or end it at once (KILL).

Cheat sheet

10 commands Printable version
  • 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

Overview

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:

text
student@ubuntu:~$ sleep 600 &
[1] 1520
student@ubuntu:~$ kill 1520
[1]+  Terminated              sleep 600

You can signal only your own processes. Others' — with sudo.

Options

7

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.

Recipes

4

End a process properly

bash
kill 1520          # TERM first
sleep 5
kill -0 1520 && kill -KILL 1520   # still alive — then KILL

TERM lets the program close files and remove temporary ones. KILL is the last resort.

End by name

bash
pgrep -a sleep           # see first who will be hit
pkill sleep              # TERM to every process named sleep
pkill -f 'app.py --dev'  # by the whole command line
killall -v nginx         # by the exact program name

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.

A service — through systemctl

bash
sudo systemctl restart nginx   # instead of kill and starting by hand
sudo systemctl kill -s HUP nginx

systemd restarts a service killed with kill if it has Restart= — see systemctl.

A process hangs in the terminal

Ctrl+C sends INT, Ctrl+Z sends TSTP (stops it and returns the prompt). After Ctrl+Z: kill %1 or fg — see background-jobs.

Troubleshooting

5

kill: (12345) - No such process

There's no process with that PID anymore: it exited, or the PID was mistyped. Find the current one: pgrep -a name.

kill: (1) - Operation not permitted

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.

The process is still listed after kill

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.

The process came back after kill

systemd or another supervisor restarts it. Check systemctl status PID and stop the service: sudo systemctl stop name.

kill: invalid signal specification

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.

Danger zone

2

kill -9 as the first move

KILL 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.

A broad pkill pattern and kill -1

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.

See also

  • pgrep — the process list before pkill with the same conditions.
  • ps — find a process's PID and state.
  • top — find a hungry process; k in top sends a signal.
  • processes — signals, states and priorities in more detail.
  • background-jobs — Ctrl+Z, jobs, fg, kill %1.
  • systemctl — stop or restart a service properly.
Loading…