Zahid Karim
Recent Posts
1.Write fast and efficient PLSQL - DBMS_PROFILER
2.Fix physically corrupt data blocks using PLSQL - DBMS_REPAIR
3.Encrypt or Decrypt sensitive data using PLSQL - DBMS_CRYPTO
4.ORA-24248 XMLDB extensible security not installed
5.Upgrade Oracle 10g Release 2 to Oracle 11g Release 1
Find me on
Install Oracle 11g Release 2 on RHEL 5 How to extract user sql statements from Oracle Trace Files

How to kill all processes with one command in Linux

Posted by Zahid on May 3, 2010.

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
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

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
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.