Kill All Processes Belonging to Any User in Linux

Hi,

Sometimes you need to kill all processes of any user in linux.

 

Normally you can kill any process from its PID like following.

 

[root@MehmetSalih ~]# ps -ef | grep OSWatcher.sh
root      4183     1  6 May02 ?        20:13:56 /bin/sh ./OSWatcher.sh 10 504 gzip /opt/oracle/oak/oswbb/archive
root     73811  4183 15 16:10 ?        00:00:00 /bin/sh ./OSWatcher.sh 10 504 gzip /opt/oracle/oak/oswbb/archive
root     73813 73811 13 16:10 ?        00:00:00 [OSWatcher.sh]
root     73816 92104  0 16:10 pts/1    00:00:00 grep OSWatcher.sh
[root@MehmetSalih ~]#
[root@MehmetSalih ~]# kill -9 4183
-bash: kill: (4183) - No such process
[root@MehmetSalih ~]#

 

 

 

But sometimes you need killing all processes of any user , then you can use following code.

[root@MehmetSalih ~]#  kill -9 `ps -ef|grep oracle | awk '{print $2}'`

 

I have used Oracle user in this example, you can change username according to your need.

 

Dont’t forget that you will have killed ALL PROCESSES OF ANY USER, so Be careful before run it.

 

For example, You have stopped Oracle EBS with adstpall.sh, but you have still EBS Process belong to applmgr, You can kill all processes of applmgr user like following.

 

[root@MehmetSalih ~]#  kill -9 `ps -ef|grep applmgr | awk '{print $2}'`



Or you can use following command.

[root@MehmetSalih ~]#  pkill -u applmgr




[root@MehmetSalih ~]#  pkill -u oracle

 

Do you want to learn Linux System Administration for Beginners, then read the following articles.

https://ittutorial.org/linux-administration-tutorial-for-beginners/

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

2 comments

  1. Careful – something like this is apt to select the wrong processes since you will match text from the whole line. Maybe you should have used formatting “ps -e -o user,pid” or use “pkill -u” which is already made for this.

  2. A construct such as ” kill -9 `ps -ef|grep oracle | awk ‘{print $2}’`” is totally not needed, just use “pkill -u oracle”. >_<

Leave a Reply

Your email address will not be published. Required fields are marked *