Kill All Process in One Step in Linux
Killing processes is something necessary in order to restart it when you cannot stop the service gracefully. Killing one process is easy but when you have more than one processes you need to kill, doing it one by one can be long.
Let's say you have multiple processes' apache running (for Intranet, Extranet, Development Environment, etc...) and you need to kill all of them at the same time.
First of all let's grab apache processes:
ps au | grep apache
This will display something like:
eric@ubuntu:~$ ps auxf | grep apache USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1545 0.0 0.2 33576 8736 ? Ss 08:02 0:00 /usr/sbin/apache2 -k start root 1547 0.2 0.3 33592 8871 ? Ss 08:03 0:00 /usr/sbin/apache2 -k start root 1548 0.1 0.2 33613 8921 ? Ss 08:03 0:00 /usr/sbin/apache2 -k start root 1550 0.0 0.3 33649 9071 ? Ss 08:03 0:00 /usr/sbin/apache2 -k start root 1553 0.3 0.2 33786 9231 ? Ss 08:03 0:00 /usr/sbin/apache2 -k start
Now we need their PID
ps au | grep apache | awk '{print $2}'
That will output only the PID list:
1545 1547 1548 1550 1553
Then kill them:
kill -9 `ps au | grep apache | awk '{print $2}'`