clickbox

Kill all processes running with same name in single command

kill-linux-process

Sometimes it difficult to kill multiple instances running for one process as first you have to list all the PID and then kill those one by one.

This time consuming task is not much difficult in Linux.

To make it simple we can use for loop, awk and kill command together.

In below command change the search patter and hit enter. It will kill all the processes with matching search pattern.

for pid in $(ps -ef | grep “search pattern” | awk ‘{print $4}’); do kill -9 $pid; done

Suppose you having following output from your ‘ps –ef|grep httpd command. Where httpd is the process and many instances running.

hostname# ps -ef|grep httpd
9628 ?           0:24 httpd
9549 ?           0:27 httpd
3712 ?          45:37 httpd
3743 ?           0:25 httpd
3744 ?           0:25 httpd
3745 ?           0:25 httpd
3746 ?           0:25 httpd
3747 ?           0:22 httpd
9579 ?           0:26 httpd
29033 ?           0:24 httpd
9580 ?           0:24 httpd

 

for pid in $(ps -ef | grep “httpd” | awk ‘{print $4}’); do kill -9 $pid; done

 

 

Please follow and like us:
20

Written by 

Sachin Kumar is an IT professional, having a good experience of Linux, Windows, Oracle, Informix, Asterisk and VoIP. Email: clickboxsachinkumar@gmail.com

,

Enjoy this blog? Please spread the word :)