Shell command for killing all the processes together, that we found using grep command

Sometime when we found a lot of process associates with a software or something that may hurt our memory or CPU, and it would be nice to kill that all process and be our system in a fine position. But when there is so many process we can’t kill all the process by hand using the command

 $ kill -9 PID

where ‘PID’ is the process id.

Shell commands will help us to do this. See below

First you create a .sh file file named ‘killAllProcess.sh’.

#!/bin/bash
echo "Usage : ./killAllProcess.sh "
for i in `ps ax | grep $1 | grep -v grep | sed 's/ *//' | sed 's/[^0-9].*//'`
do
  kill -9 $i
done
echo "Killed All the process which has name with $1"

And make this file executable

$ chmod +x killAllProcess.sh 

Then run it

 $ ./killAllProcess.sh 

And see any process with that name is there

$ ps aux | grep PROCESS_NAME

All vanishes..!!

Advertisements

Author: Abhi

Hi, this is Abhilash - Senior Programmer Analyst at CoMakeIT, specialised on web programming. Mainly working on Ruby On Rails platform since 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s