How to terminate multiple running processes simultaneously
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 &
With the above command we have started process with job ID "1" and PID 5322. Let's start few more processes:
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
PID TTY STAT TIME COMMAND
5405 pts/0 R 3:54 yes
To kill all above process we can use pkill or killall commands: