How ToLinux

How to Kill A Process in Linux using Command Lines

A complete guide on linux kill process.

Linux is the widely used open-source operating system built-in with many software programs. There are various types of programs which are either run by its user or the operating system. These running programs on Linux are called Processes. If a process may not be good or misbehaves, you need to kill or terminate the unwanted process. It can be done without any log and you don’t need to restart the device. You are allowed to force kill the process from both internal and external storage. You can use the kill command to terminate the unnecessary process on your Linux devices.

Techowns Tip: How to Remove/Delete Directory in Linux

In order to kill a process, you first need to locate the process information.

Locate the Process

You can locate the process through different commands such as top, ps, pidof and pgrep.

Locating the Process Using Top Command

The top command on Linux helps you to get all the currently running process. You can open the terminal either from the system dash or the through the keyboard shortcut Ctrl+Alt +T. It will display the list of running process, here you have to select the name of the process that you want to kill. Select the PID of the process and the name of the process will be shown on the right side.

Kill A Process in Linux

Locating the Process Using ps and grep Commands

It is another way to find the unwanted process from your Linux device. Open the Terminal app and use the ps command along with grep command.

$ ps aux

Now the output will be shown similar to the top command output. In this, the PID column appears second from the left, where the process name appears first. You can find your process easily on ps command with the help of grep command. It will show all the related process.

ps aux | grep

Locating the Process Using ps and grep Commands

Locate the Process via pidof and pgrep

Open the terminal and enter the pidof command along with the process name which you want to kill.

pidof nginx

It will show the exact result of your search, if there are many processes in your search name, all of them will be displayed.

Kill Process on Linux

There are four commonly used Kill commands used to delete the process. They are the kill, killall, pkill and Xkill. You kill the unwanted process by name or PID or select the process from the list.

1) Kill Command

You can use the Kill command to delete the process by finding them manually. It can be done by entering the process name or number as signal. You need to enter the kill command followed by the locate command.

$ ps aux | grep firefox

$ kill -firefox

$ kill -9 <process name>

2) Killall Command

You can use the killall command to kill all the process running on a particular period of time.

To kill the process by using the name,

$ killall <process name>

To kill the process with SIGKILL,

$ killall -9 <process name>

If there are a number of processes available in the particular search result, and you want to kill all the process one by one, you have to use the following command,

$ killall -i <process name>

Here you have to use -i instead of the number.

If you want to kill the process running as a different user, you need to use sudo in front of the command line.

$ sudo killall <process name>

If you want to kill the process running for more than thirty minutes, you have to use the -o within your command.

$ killall -o 30m <process name>

If you want to kill the process running for less than 30 minutes, you have to use -y in between your kill command line.

$ killall  -y 30m <process name>

3) Pkill command

Pkill command is the simplest way to kill the processes. Here you have to specify the full name or partial name of the process. Also, you don’t need to find out and enter the PID of the process you want to kill.

$ pkill <process name>

4) Xkill Command

Xkill is the best command to kill the malfunctioning process. It is used to kill a process on the X server without entering the process name or PID. You can use this command to kill the client conversation, once the communication is over.

$ xkill <client windows you wish to kill>

Our Opinion

Kill or terminate the erring or harmful process from your Linux device using any of these command lines. You need to know the process name and PID to kill the process. Wind up the unwanted process from your device to be risk free. Terminating the process will help you to manage your system efficiently.

Leave your queries in the comments if any. Follow us on Twitter and Facebook for more updates.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *