How to Kill a Process in Linux Easily

x32x01
  • 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.

💡 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 💣
⚠️ Tip: Always try SIGTERM before SIGKILL. The latter doesn’t let programs save their data!



👀 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 -aux

The 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
These commands return the PID (Process ID), which you’ll use to kill it.



⚔️ 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
or
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: xkill
Then click on the unresponsive window 💥 - problem solved!



🧾 Quick Recap​

  • Use top, ps, or pgrep to find the process.
  • Use kill, killall, or pkill to terminate it.
  • Use sudo for permission issues.
  • Use kill -9 only 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: