Imagine you are working on your Linux server, and suddenly an application freezes, refuses to close, or starts using way too much CPU or memory. No matter how many times you click “close,” it just won’t listen.
This happens to everyone, even experienced Linux users!
The good news is that Linux gives you powerful commands to find and kill such processes instantly.
In this guide, we will walk you through simple, clear steps to safely kill a process in Linux using various commands, keeping your server smooth and responsive.
Let’s get started!
Also Read: How to Check CPU Usage in Linux?
What is a Process in Linux?
A process is simply a program that is currently running on your server. Every process has a PID (Process ID) — a unique number that helps Linux identify it.
To kill a process, we mainly use its PID.
When Should You Kill a Process?
You should only kill a process when:
- It is frozen or not responding.
- It is consuming too much CPU or memory
- It is causing a server slowdown
- You want to restart or stop a service manually.
- A program has hung or crashed
Also Read: How to Check Memory in Linux?
Steps to Kill a Process in Linux
➢ Step 1: Check Running Processes
Before killing anything, you need to know what’s running. Linux provides several commands to view active processes.
1. Using the ps command
➔ The ps command shows the currently running processes in your terminal session:
| ps |
To see all server processes with detailed information, use the following command:
| ps aux |
a – It shows processes from all users
u – It displays detailed info like CPU and memory usage
x – It includes processes not attached to a terminal
You will see a list with columns like USER, PID, CPU%, MEM%, and COMMAND.
2. Using the top command
➔ The top command shows a live, real-time view of all processes:
| top |
➔ In this, you can scroll, sort, and watch activity change in real time.
3. Using the htop command (if installed)
➔ The htop command is a more user-friendly, colorful version of top:
| htop |
You can kill a process directly by selecting it and pressing F9.
Also Read: How to Check OS Version in Linux?
➢ Step 2: Find the Process You Want to Kill
Once you have the list of running processes, search for the process by its name or check its resource usage.
➢ Find a process by name using pgrep
➔ If you know the process name (like Apache, nginx, Firefox, etc.), you can use this command:
| pgrep processname |
For Example:
| pgrep firefox |
This will show the PID(s) for that process.
➢ Search using ps and grep
➔ If you want to search from the process list manually:
| ps aux | grep processname |
For Example:
| ps aux | grep nginx |
➢ Step 3: Kill a Process Using the kill Command
➔ Once you have the PID, the quickest method is to use the kill command.
1. Kill a process normally
➔ To kill a process normally, you have to use the following command:
| kill PID |
Example:
| kill 1450 |
This sends a safe termination signal (SIGTERM), allowing the process to close gracefully.
2. Force kill a process
If a process refuses to stop, you have to use:
| kill -9 PID |
- -9 is SIGKILL, a powerful force-stop signal.
- The process stops immediately without cleanup.
Example:
| kill -9 1450 |
Use this only when a normal kill doesn’t work.
3. Kill a Process by Name Using pkill
Instead of searching for the PID, you can kill a process directly by its name.
| pkill processname |
For Example:
| pkill firefox |
This will kill all processes with the given name.
4. Kill All Processes of a User
If you want to stop all processes belonging to a particular user, you have to use the following command:
| pkill -u username |
For Example:
| pkill -u john |
This is useful for managing logged-in accounts or cleaning up zombie processes.
5. Kill a Process from the top Command
Inside the top command:
| top |
- Press k (for kill)
- Enter the PID
- Press Enter to kill
This is a quick method if you are already monitoring performance in real-time.
Also Read: How to Check OS Kernel Version in Linux?
Common Kill Signals Explained
Signal |
Number |
Description |
|---|---|---|
SIGTERM |
15 |
Safe, polite request to close (default) |
SIGKILL |
9 |
Forced kill, cannot be ignored |
SIGSTOP |
19 |
Pause/stop a process |
SIGCONT |
18 |
Resume a stopped process |
You rarely need more than SIGTERM and SIGKILL.
Conclusion
Killing a process in Linux is simple once you understand how processes work and how to find their PID. Whether it’s a frozen application or a misbehaving service, Linux gives you complete control through commands like kill, pkill, top, and pgrep.
By following the steps in this guide, you can quickly identify and stop any unwanted processes, keeping your server stable and efficient.
If you are managing a server, knowing these commands will save you a lot of time and frustration.
Happy Linux-ing!
