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
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
 5405 pts/0    R      3:54 yes
To kill all above process we can use pkill or killall commands:
$ pkill yes
$ 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