At any given moment your Linux system is running multiple processes simultaneously. Therefore, it is an important skill to know how to manage processes and how to terminated them if the need arises. The process can be terminated with various command such as, kill, killall, pkill. In this short guide we explain how to terminate multiple processes with a single command. First, let's see how we can start process and what information we are able to acquire for any given process.
$ yes > /dev/null &
[1] 5322
With the above command we have started process with job ID "1" and PID 5322. Let's start few more processes:
$ yes > /dev/null &
[2] 5402
$ yes > /dev/null &
[3] 5403
$ yes > /dev/null &
[4] 5404
$ yes > /dev/null &
[5] 5405
In order terminate all processes we use tools such as killall or pkill. How it works is that we kill all processes based on their name. To try your regular expression use pgrep command:
$ pgrep yes
5322
5402
5403
5404
5405
Based on the regular expression which in this case is a string containing name of the actual yes command we are able list all PID's for all processes matching this criteria. To get a process information based on its PID we can use ps command.
$ ps 5405
  PID TTY      STAT   TIME COMMAND
 5405 pts/0    R      3:54 yes
To kill all above process we can use pkill or killall commands:
$ pkill yes
OR
$ killall yes
[1]   Terminated              yes > /dev/null
[3]   Terminated              yes > /dev/null
[5]+  Terminated              yes > /dev/null
[2]-  Terminated              yes > /dev/null
[4]+  Terminated              yes > /dev/null


Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top