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 .

killall Command Syntax

The syntax of the killall command is like below.

Usage: killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME... 
       killall -l, --list 
       killall -V, --version

killall Command 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.

$ killall -h

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 processes in the system where the user-related process will generally list in the below of the output.

$ ps uax
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.

$ ps uax | grep "watch ls"

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.

$ killall watch

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.

$ ps uax | grep "watch ls"
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.

$ killall -e "watch"
Kill With Exact Process Name
Kill With Exact Process Name

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

LEARN MORE  Python Glob() Function To Match Path, Directory, File Names with Examples

Ignore Casesensitivity 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 casesensitivity 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.

$ killall -I WATCH
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.

$ killall -u ismail
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.

$ killall -g ismail

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.

$ killall -i watch

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

$ killall -o 1m watch

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

$ killall -y 5h watch

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
LEARN MORE  How To Grep Text Files With Powershell Grep or Select-String Cmdlet In Windows?

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.

$ killall -r "w.*h$"
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 thoughts on “Killing Linux Processes With killall Command”

  1. 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.


Leave a Comment