Killing a process in Linux is a way to stop the process from running and releasing resources. It is useful to improve system performance by ending those processes that occupy CPU or memory resources in a large amount.
In Linux, there are different ways to kill a process. The purpose of this guide is to explain 5 quick ways to kill a process in Linux:
- Using the kill Command
- Using the killall Command
- Using the pkill Command
- Using the xkill Command
- Using the top or htop Command
Let’s start the article with the kill command.
Method 1: Using the kill Command
The kill command is utilized to send an alert to a process for terminating the specific process. The process ID is required to kill the particular process, which the user wants to terminate.
Let’s see the running processes in the current system via the “top” command and target one of them:
In our case, kill the “firefox” process by specifying the process id “3514” as shown in the below command:
$ kill 3514
After the execution of the above command, the particular process has been terminated via process id.
Method 2: Using the killall Command
The killall command terminates all processes by specifying the process name. For instance, terminate the “top” process by executing the below command:
$ killall top
The output shows that the running process of the “top” command has been terminated.
Method 3: Using the pkill Command
The pkill command specifies the signal sent to the particular process. To kill a process, use the “pkill” command by mentioning the process name.
For instance, kill the “firefox” running process by passing the “9” signal that will forcefully terminate the process:
$ pkill -9 firefox
The output shows that the “firefox” process has been forcefully terminated
Method 4: Using the xkill Command
The xkill command allows you to kill a process by clicking on the window of the process. To use the xkill command, type xkill in the terminal and then click on the window of the process you want to terminate.
In our case, specify the process name:
The output shows that you select the particular window for which you want to terminate the process by pressing the mouse button.
Method 5: Using the top or htop Command
The top or htop commands allow you to view running processes and kill them by pressing “k” and then entering the process ID of the process you want to terminate. Pressing “q” will exit the top or htop command. In our case, type the “5985” process id to kill the running process in the system:
The output shows that the “top” process has been terminated by specifying the process id.
To kill a running process in Linux, the “kill”, “kilall”, “pkill”, “xkill”, and “top” commands are utilized.
All these above commands require the process name or id to kill the particular process. Following these commands allows users to free the RAM and CPU resources by terminating processes. This article has explained all possible ways to kill the process in a very short time.