Dec 02, 2025
Ariffud M.
9min Read
In Linux, managing running processes is key to maintaining system performance and stability. If you encounter an unresponsive or misbehaving process, you can kill it using various commands.
To kill a process in Linux, you can use the kill command, specifying either the Process ID (PID) or the process name. The kill command sends signals to processes, asking them to terminate or forcing them to stop.
Additionally, other commands like killall and pkill also help facilitate process termination based on the process name, offering greater flexibility in terminating multiple processes at once.
Each of these commands has different options for sending signals, either gracefully terminating a process or forcefully stopping it. In this article, we will explore each of these commands and show you how to use them effectively in various scenarios.
Before learning how to kill a process in Linux, make sure to follow these prerequisites:
sudo apt-get install procps x11-utils # for Debian-based distributions
sudo yum install procps-ng xorg-x11-apps # for Red Hat-based distributions

You must first locate the correct process to avoid accidentally stopping essential system operations. Here are several commands to find details of running processes in Linux:
Locate a process with ps
The ps command provides a complete listing of running processes and their details, such as the user, process ID (PID), CPU and memory usage, and the command that started the process.
Here’s its basic syntax:
ps [options]
You can append these options to this command:
For example, if you execute the following:
ps -aux
You should see an output similar to:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169364 8824 ? Ss Jul08 0:05 /sbin/init
root 2 0.0 0.0 0 0 ? S Jul08 0:00 [kthreadd]
...
Find PID with pidof
The pidof command finds the process’s PID by name. It’s simple and handy when you already know the exact process name.
pidof [options] [program]
Some helpful options for pidof include:
For instance, to get the PID of sshd, run:
pidof sshd
If there is only one instance running, the output will be a single PID:
1234
However, if more than one instance is running, it will display multiple PIDs:
1234 5678
Find PID with pgrep
The pgrep command offers a more advanced way to find a process. It returns processes based on specific selection criteria that can match process names, known as a pattern.
pgrep [options] [pattern]
Here are some common options you can add:
For example, to display the names and PIDs of all processes owned by the user john, you can use:
pgrep -lu john
The above command will return:
1234 process_name_1
5678 process_name_2
...
View running processes with top
The top command provides an interactive, real-time view of running processes. It shows the PIDs, users, amount of memory and CPU power each process uses, and running time.
To view a list of all active processes, run:
top
Here’s an output you would see:
top - 15:37:58 up 2:13, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni, 100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 4045860 total, 3810124 free, 140408 used, 94808 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 3643028 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 169364 8824 6508 S 0.0 0.2 0:05.14 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
...
To exit the top interface, press Q.
Hostinger users can list processes in their VPS without commands by asking the Kodee AI assistant. Simply enter a prompt like, “Show all processes and their PID owned by the user root” and Kodee will output the corresponding processes.
kill command signals are messages sent to processes to instruct them to perform specific actions. They are a fundamental part of Unix-based operating systems, allowing users and programs to control processes effectively.
You can view all available signals on Linux with the command below:
kill -l
It lists all signals along with their corresponding numbers and names, such as:
For instance, to kill a process with SIGTERM, execute the following:
kill -15 [PID]
The importance of choosing the appropriate signal
Using the correct kill signal based on the scenario and the desired impact ensures that processes are terminated in a controlled and predictable manner, especially when dealing with background tasks.
For example, the SIGTERM signal is preferred for safe process control, letting processes carefully save their state and exit. SIGKILL, while practical, should be sparingly used as it may lead to data loss or corruption.
Follow our article to learn about some of the most commonly used Linux commands, strengthening your skills and familiarity with this operating system.
If you know the PID of the process you want to terminate, you can easily use the Linux kill command to send a signal. The following is its basic syntax:
kill [signal] PID
For example, to ask the process to end with the default SIGTERM signal and PID 1234, execute:
kill -15 1234
If the process does not respond to SIGTERM, try using the SIGKILL signal to terminate it forcefully:
kill -9 1234
You can also send other signals based on your specific needs, such as:
kill -2 1234 # Sends SIGINT
kill -1 1234 # Sends SIGHUP
If you need to kill multiple processes at once, the kill command allows you to send signals to multiple PIDs. Here’s how:
kill [signal] PID1 PID2 PID3
Here’s an example of ending processes with PIDs 1234, 5678, and 91011 using SIGTERM:
kill -15 1234 5678 91011
To send a signal to all processes in a group, use the negative PID of the group leader:
kill -15 -1234
This kills all processes in the group led by PID 1234.
Be cautious when terminating parent processes, as doing so may also kill any child processes associated with it.
The pkill command allows you to kill processes by name, often faster than using the kill command with a PID. Here’s how you can use pkill:
pkill [signal] [process name]
For example, to kill a process named nginx, run:
pkill -SIGTERM nginx
If you want to terminate processes owned by a specific user:
pkill -u john
For instance, to end processes associated with a terminal pts/1:
pkill -t pts/1
You can also kill all processes in a specific process group, for example, PGID 1234:
pkill -g 1234
To terminate the newest or oldest instance of a process, type the following:
pkill -n nginx # Kill the newest instance of nginx
pkill -o nginx # Kill the oldest instance of nginx
You can also combine multiple options to match processes based on specific criteria. For example, to kill processes from user john on terminal pts/1 in process group 1234 at once, execute the following:
pkill -u john -t pts/1 -g 1234
killall terminates all instances of a process by name and can target processes based on age, user, and running time.
It’s ideal to manage processes with the same name across the system, compared to kill for individual processes and pkill for selectively managing multiple instances of a process.
The basic syntax of the killall command is:
killall [options] [process_name]
Here are some of its primary uses:
killall nginx # Terminates all instances of nginx
killall -s SIGKILL nginx # Forcefully kills all instances of nginx
killall -u john nginx # Ends all nginx processes owned by the user john
If you want to kill processes that have been running for a specific duration:
killall -o 1h nginx
This kills all nginx processes running for more than one hour.
To kill all instances of a process except a specific one:
killall -v -I nginx
You can exclude a specific nginx process from being killed with the above command.
Furthermore, to kill processes based on their CPU load or memory usage:
killall -i -s SIGKILL nginx
This sends an interactive prompt before killing each nginx process so you can confirm or deny each action.
The xkill command is designed for GUI-based environments like a Linux-installed laptop. With it, you can kill applications that have frozen or don’t respond to standard termination commands with a simple click.
Here are some scenarios where xkill proves handy:
To use xkill, enter this command in your terminal:
xkill
After executing this command, your mouse cursor will change to an × icon. Then, move the cursor to the window of the unresponsive application and right-click on it. This will immediately kill the selected process.
Alternatively, if you know the unresponsive application’s window ID, type:
xkill -id <window_id>
With this command, you can target and kill a specific window directly.
Please note that xkill doesn’t natively support killing by class or name. However, you can use other tools in conjunction with it to achieve similar results. For example, use wmctrl to list windows and their IDs, and then run xkill with the appropriate ID.
To install wmctrl, run:
sudo apt-get install wmctrl
Once done, list all windows and their IDs:
wmctrl -l
The output will look something like this:
0x03c00003 0 hostname Firefox
0x04a00004 0 hostname Terminal
0x05000005 0 hostname Code
Then run xkill with the desired ID, for instance:
xkill -id 0x03c00003
The top command provides a real-time, interactive view of resource usage and running processes. It’s handy for identifying and terminating processes that consume excessive resources or become unresponsive.
As previously explained, you can type top in your terminal to start it. To navigate through the list of processes, use the arrow keys. Press Shift + P to sort processes by CPU usage, while Shift + M sorts them by memory usage.
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 169364 8824 6508 S 0.0 0.2 0:05.14 systemd
512 user 20 0 120364 6024 2508 S 1.0 0.1 0:02.04 firefox
789 user 20 0 140364 7624 3208 R 2.0 0.3 0:03.22 chrome
...
Once you’ve identified the process you want to end, press K.
top will prompt you to enter the process’ PID you wish to kill. Then, you need to specify the signal to send to the process.
Press Enter to send the default SIGTERM signal, or type a different signal number if required.
For instance, to kill the chrome process with PID 789 using SIGKILL:
k
PID to kill: 789
Send signal (15): 9
Additionally, to view processes owned by a specific user, start top with the -u option like the following:
top -u john
You can also customize the columns displayed within top by pressing F. This way, you can add or remove columns and sort by different criteria.
In this article, we covered various methods for terminating processes in Linux, including the kill, pkill, killall, xkill, and top commands. Each command offers different functionalities, allowing you to use them according to your needs.
Carefully managing processes is essential for maintaining system performance and stability. By familiarizing yourself with these commands, you can effectively handle unresponsive applications and optimize resource usage.
Lastly, always verify the processes you terminate to avoid accidental system issues and ensure your Linux machine runs smoothly.
This section answers some of the most common questions about killing a process in Linux.
You can kill both user and system processes in Linux. User processes owned by the user can generally be killed without issues. System processes owned by the system or root user require root permissions to kill and should be handled cautiously, as terminating them can cause system failure.
The kill command requires a PID and terminates a specific process, making it ideal for precise control. Meanwhile, the killall command terminates all instances of a process by name, offering more flexibility for managing processes with the same name across the system.
You can find the PID of a process using the ps, pidof, pgrep, or top commands. For example, use ps aux, pidof [process_name], pgrep [process_name], or top to list process IDs and details.
Comments
December 21 2020
You can also use lsof to get a list of ports as is shown here! https://fjolt.com/article/linux-how-to-kill-process-at-port