- by x32x01 ||
When a Linux process goes rogue or eats up too much CPU/RAM, you’ve got to terminate it manually 🔪 - that’s where kill commands come in handy! In this guide, you’ll learn all the ways to kill processes in Linux using the terminal like a real sysadmin.
If you’re not root, just type
There are a few signal types to end a process:
The options mean:
These commands return the PID (Process ID), which you’ll use to kill it.
Optional flags:
To force kill:
or
🚨 Warning:
Then click on the unresponsive window 💥 - problem solved!
👉 Learn about the nohup command - it blocks signals like SIGHUP so your processes don’t die when the terminal closes.
💡 What You Need to Know Before Killing a Process
In Linux, only root (or a user with sudo privileges) can terminate any process.If you’re not root, just type
sudo before the command.There are a few signal types to end a process:
- SIGTERM - A polite “please close” request 😅
- SIGKILL - A forceful “close now!” command 💣
👀 Step 1: View All Running Processes
Use the top command to see everything currently active:top- Press k to kill a process directly from the list.
- Press q to quit.
🔍 Step 2: Find the Process You Want to Kill
✅ Using ps Command
Shows running processes with detailed info:ps -auxThe options mean:
-a: all users-u: detailed info-x: system/daemon processes
✅ Using pgrep or pidof
If you know part or all of a process name: Bash:
pgrep -u root apache
pidof firefox ⚔️ Step 3: Kill the Process
🧩 Using killall
Kill processes by name: Bash:
sudo killall firefox Optional flags:
-i: ask for confirmation-v: show results-o 10m: kill processes older than 10 minutes
🎯 Using pkill
Similar to pgrep, but it actually kills the process: Code:
sudo pkill -u root apache 💀 Using kill by PID
When you have the process ID: Code:
sudo kill 1234 To force kill:
Code:
sudo kill -9 1234 Code:
sudo kill -SIGKILL 1234 🚨 Warning:
kill -9 skips cleanup routines - data loss possible!🖱️ Step 4: Use GUI or xkill (For Desktop Users)
If you’re using a graphical environment, type:xkillThen click on the unresponsive window 💥 - problem solved!
🧾 Quick Recap
- Use
top,ps, orpgrepto find the process. - Use
kill,killall, orpkillto terminate it. - Use
sudofor permission issues. - Use
kill -9only when nothing else works.
🧩 Bonus Tip
Want to keep a command running even after logout?👉 Learn about the nohup command - it blocks signals like SIGHUP so your processes don’t die when the terminal closes.
Last edited: