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
The syntax of the killall command is like below.
Usage: killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME...
killall -l, --list
killall -V, --version
Simple and fast help information about the command can be listed like 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
As killall provides convenient ways to kill 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 user related process will generally listed in the below of the output.
$ ps uax
Now we can start kill processes according their name. This example is a simple example where we only provide some term which is 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 the process and see that is killed.
$ killall watch
Kill With Exact Process Name
In 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 similar named processes. We can specify exact name to exactly specify the process. In this example we have two process with similar name as we can see below.
$ ps uax | grep "watch ls"
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 too match exact name of the process like below.
$ killall -e "watch"
We check again the running processes and see only
Ignore Case For Process Name
While killing processes the name of the processes is important. The processes name can be upper case or lowercase which is not deterministic. In this situations using ignore case parameter is important.
-I parameter can be provided to ignore case like below. In the example below we can see that there is instance of
watch . We will kill by providing uppercase
WATCH term like below.
$ killall -I WATCH
Kill According To Process Owner or User Name
As we know every Linux process have a 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 this examples we want to kill user name
$ killall -u ismail
As we see we have killed also our ssh session which user name was ismail too.
Kill According To Process Group Name
As we know every Linux process have a owner group name. And this feature is same as killing according to 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 options is defined also interactively because of its usage way. While killing process 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 runs more than 1 minutes. This options is
$ killall -o 1m watch
Also we can kill processes less than specified time. This is feature is expressed as
$ killall -y 5h watch
We can below how the time is expressed for this feature.
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 those are similar but not the same. Regular expressions is the way to express structural parts in the text. In this example we will kill all processes those starts with
w and ends with h .
$ killall -r "w.*h$"
In this example only the
watch processes is killed because we have restricted regular expression that the end of the processes name must be