Killing Linux Processes With killall Command – POFTUT

Killing Linux Processes With killall Command

We have previously looked the command kill to kill process accordion to their names, owners, etc. But using only kill command to kill a process according to its owner is done with supportive commands like grep. In this tutorial, we will look more compact and all in one command killall .

Syntax

The syntax of the killall command is like below.

Syntax

Syntax

Help

Simple and fast help information about the command can be listed below. As we see below killall command provides features like exact process name match, ignoring case, interactive usage, verbose or debug mode operation.

Help

List Process With ps

Killall provides convenient ways to kill a process with its name listing process and using complete process names will make killall operations more reliable. We will list all process in the system where the user-related process will generally list in the below of the output.

List Process With ps

List Process With ps

Kill Process

Now we can start kill processes according to their name. This example is a simple example where we only provide some term which resides in the process name. Our process is watch ls like below.

Kill Process

Kill Process

Now we can provide the term watch to the killall command like below. And after that command, we can process and see that is killed.

LEARN MORE  How To Add User To A Group In Linux

Kill Process

Kill Process

Kill With Exact Process Name

In the previous example, we have only provided some part of the process name, not the whole. In some situations, this can not be suitable because of similarly named processes. We can specify the exact name to exactly specify the process. In this example, we have two processes with similar names as we can see below.

Kill With Exact Process Name

Kill With Exact Process Name

Now we only want to kill process watch ls which PID is 3733 . But we do not want to kill watchgnupg which PID is 3732 .

Now we will provide process name with the -e parameter to match the exact name of the process like below.

Kill With Exact Process Name

Kill With Exact Process Name

We check again the running processes and see only watchgnupg process.

Ignore Case For Process Name

While killing processes the name of the processes is important. The process name can be upper case or lowercase which is not deterministic. In these situations using ignore case parameters is important. -I parameter can be provided to ignore case like below. In the example below, we can see that there is an instance of watch . We will kill by providing uppercase WATCH term like below.

Ignore Case

Ignore Case

Kill According To Process Owner or User Name

As we know every Linux process has an owner user name. Killall command supports killing processes according to their user names. Keep in mind that this will kill all processes of the specified user. In these examples we want to kill user name ismail processes.

LEARN MORE  What Is User In Computing, Windows, Linux, Google?

Kill According To Process User Name

Kill According To Process User Name

As we see we have killed also our ssh session which the user name was ismail too.

Kill According To Process Group Name

As we know every Linux process has an owner group name. And this feature is the same as killing according to the user name. We only provide the group name of the processes with the -g option like below.

Confirm Before Killing Processes

Up to now, we have killed processes harshly without warning of a confirmation. There is an option to ask about confirmation while killing processes like below. The option is -i . This option is defined also interactively because of its usage way. While killing processes also the PID is provided for stability.

Get Confirmation Before Killing Processes

Get Confirmation Before Killing Processes

Kill Processes According to Running Time

There is another interesting feature of the killall command. Processes can be killed according to their run time. In this example, we will kill all processes that run more than 1 minute. This option is -o

Also, we can kill processes less than specified time. This is feature is expressed as -y option.

We can below how the time is expressed for this feature.

  • s  seconds
  • m minutes
  • h hours
  • d days
  • w weeks
  • M months
  • y years

Using Regular Expression For Process Names

Up to now, we have used specific processes names. This is simple to express but there are times where we need to expresses generic processes names that are similar but not the same. Regular expressions are the way to express structural parts in the text. In this example, we will kill all processes that start with w and ends with h .

LEARN MORE  How To Generate and Configure Htpasswd Password In Linux For Apache and Nginx Server?

Using Regular Expression For Process Names

Using Regular Expression For Process Names

In this example only the watch processes are killed because we have restricted regular expression that the end of the processes name must be h . So only watch processes are matched and killed.

2 Responses

  1. Sven says:

    First I become root then I use the order “top” in order to see the process name (in most cases when the fan of the computer is louder as normal) and then I kill the process with “killall -9 name” and the process stops.

  1. 15/07/2019

    […] DAHA FAZLASI BİLGİ İÇİN … […]

Leave a Reply

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