Ever had a frozen application or a rogue script that just won't die? Knowing how to properly terminate a process is a fundamental skill for any Linux user, developer, or sysadmin.
This cheatsheet covers four essential commands to handle any unresponsive process: kill
, killall
, pkill
, and the powerful fuser
for network ports.
Part 1: Kill by Process ID (PID) - The Classic Way
This is the most precise method. First, you find the Process ID (PID), then you send a signal to it.
Copy-Paste Version:
First, find the Process ID (PID) of your app:
ps aux | grep 'my_process'
Then, kill the process by its PID:
Sends a "graceful shutdown" signal (SIGTERM 15)
kill PID_NUMBER
If it doesn't work, force kill the process:
Sends an "ungraceful kill" signal (SIGKILL 9)
kill -9 PID_NUMBER
Part 2: Kill by Name - The Convenient Way
These commands are perfect when you don't want to look up the PID first.
Copy-Paste Version:
Kill a process by its exact name:
Note: killall is very strict with the name
killall my_process
Force kill a process by its exact name:
killall -9 my_process
A more flexible way to kill by name (finds partial matches):
pkill -f 'my_process_or_script.py'
Part 3: Kill by Port Usage - The Network Way
Incredibly useful for web developers and sysadmins when a port is unexpectedly occupied.
Copy-Paste Version:
Find and kill the process using a specific port (e.g., 8443):
The '-k' option sends the SIGKILL signal by default
fuser -k 8443/tcp
Downloadable version:
Source & downloads:
You can find the original PNG version of this cheatsheet in the original post:
How to kill a process in Linux: A cheatsheet (kill
, killall
, pkill
, fuser
)
Top comments (0)