Tuesday, January 15, 2013

How to kill all processes with one command in Linux


 kill all processes with one command in Linux

$ 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 oracle 4679 1 0 18:18 ? 00:00:01 ora_cjq0_oraxpo oracle 4681 1 0 18:18 ? 00:00:06 ora_mmon_oraxpo oracle 4683 1 0 18:18 ? 00:00:01 ora_mmnl_oraxpo oracle 4685 1 0 18:18 ? 00:00:00 ora_d000_oraxpo oracle 4687 1 0 18:18 ? 00:00:01 ora_d001_oraxpo oracle 4689 1 0 18:18 ? 00:00:00 ora_d002_oraxpo oracle 4691 1 0 18:18 ? 00:00:06 ora_s000_oraxpo oracle 4713 1 0 18:18 ? 00:00:00 ora_arc0_oraxpo oracle 4715 1 0 18:18 ? 00:00:02 ora_arc1_oraxpo oracle 4719 1 0 18:19 ? 00:00:00 ora_qmnc_oraxpo oracle 4735 1 0 18:19 ? 00:00:01 ora_q000_oraxpo oracle 4749 1 0 18:19 ? 00:00:00 ora_q001_oraxpo oracle 7631 1 1 18:30 ? 00:00:01 ora_j000_oraxpo oracle 7674 4613 0 18:32 pts/1 00:00:00 grep oraxpo

$ 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
4691
4713
4715
4719
4735
4749
7720

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.

No comments:

Post a Comment