Original: http://oracleflash.com/20/How-to-kill-all-processes-with-one-command-in-Linux.html
Some time you may need to kill a certain number of processes initiated by any application in Linux. To kill a process you have to provide the process id to the “kill” command and the process should be terminated. In this post I will demonstrate how to kill multiple processes with one command.
I have an oracle instance running with the name “oraxpo”. The following command will show all running processes where the term “oraxpo” is used in the process name.
$ ps -ef | grep oraxpo oracle 4663 1 0 18:18 ? 00:00:00 ora_pmon_oraxpo oracle 4665 1 0 18:18 ? 00:00:00 ora_psp0_oraxpo oracle 4667 1 0 18:18 ? 00:00:01 ora_mman_oraxpo oracle 4669 1 0 18:18 ? 00:00:00 ora_dbw0_oraxpo oracle 4671 1 0 18:18 ? 00:00:03 ora_lgwr_oraxpo oracle 4673 1 0 18:18 ? 00:00:02 ora_ckpt_oraxpo oracle 4675 1 1 18:18 ? 00:00:11 ora_smon_oraxpo oracle 4677 1 0 18:18 ? 00:00:00 ora_reco_oraxpo
Now to kill a process we need to provide the process id which are shown in the second column of above output. The following command kills the process with the id 4663 which is the Oracle background process PMON.
$ kill -9 4663
This way we can kill all process but the problem is that we will have to provide all process id’s to the “kill -9” command separated with a space. e.g. to kill first three process we will use “kill -9 4663 4665 4667”. Or we can come up with a way where all process id’s for oraxpo should be passed to kill -9 automatically.
The following command prints the second column in the output of processes which contains oraxpo in their name.
$ ps -ef | grep oraxpo | grep -v grep | awk '{print $2}' 4665 4667 4669 4671 4673 4675 4677 4679 4681 4683 4685 4687 4689
Now all we need to do is to pass the result of this command to “kill -9”.
$ kill -9 `ps -ef | grep oraxpo | grep -v grep | awk '{print $2}'`
NOTE: Please don’t try this unless you have tried every thing else and there is no way else left then killing oracle like this.
After we execute this command let’s see if we still have any process containing oraxpo in their name.
$ ps -ef | grep oraxpo oracle 7804 4613 0 18:36 pts/1 00:00:00 grep oraxpo
As can be seen from the output above there is no oracle process running.