How to Kill a Process on Linux
Stop runaway or frozen processes on Linux using kill, killall, and pkill — including how to find a process ID and choose the right signal.
Finding Processes to Kill
Before you can kill a process, you need its PID (Process ID). There are several ways to find it:
ps aux | grep firefox # list all processes, filter by name
pgrep firefox # print PIDs of matching processes
pidof nginx # print PID of a named program
top # interactive process list (q to quit)
htop # better interactive list (install: sudo apt install htop)
kill — Send a Signal by PID
The kill command sends a signal to a process. The default signal is SIGTERM (15), which asks the process to shut down gracefully:
kill 1234 # graceful shutdown (SIGTERM)
kill -9 1234 # force kill (SIGKILL) — no cleanup
kill -15 1234 # explicit SIGTERM
Always try kill PID first. Only use kill -9 if the process ignores the graceful signal — SIGKILL cannot be caught or ignored by the process.
killall — Kill by Name
killall kills all processes matching a name, saving you from finding PIDs:
killall firefox
killall -9 chrome # force kill all Chrome processes
killall -u alice # kill all processes owned by user alice
pkill — Kill by Pattern
pkill is like killall but matches against a pattern and supports more options:
pkill firefox
pkill -9 java
pkill -u bob # kill all of bob's processes
pkill -f "python script.py" # match against the full command line
Signals Explained
- SIGTERM (15) — politely ask the process to stop. Default signal.
- SIGKILL (9) — immediately terminate. Cannot be caught or ignored.
- SIGHUP (1) — reload config (many daemons respond to this)
- SIGINT (2) — same as pressing Ctrl+C in the terminal
Kill a Process Using the Most Port
Find what's listening on a port and kill it:
sudo lsof -i :3000 # find process on port 3000
sudo ss -tlnp | grep 3000 # alternative
# then kill the PID shown
kill 5678
Using top or htop
In top, press k, enter the PID, then choose a signal. In htop, select a process with arrow keys and press F9 to choose a signal, or F10 to quit.