TECH SOLUTIONS

Click here to edit subtitle

Forums

Post Reply
Forum Home > Unix Learnings > Script - Kill multiple processes of same name

Sourav Gulati
Site Owner
Posts: 83

#!/bin/bash

echo "Enter process name (or part of process name)"

read pname

 

noOfInstances=`ps -ef | grep $pname | grep -v grep | wc -l`

echo $noOfInstances

 

# ps -ef | grep $pname | grep -v grep | cut -d" " -f2 > ~/Documents/Linux/s-killMultiPs/pnames.log

 

ps -ef | grep $pname | grep -v grep | awk '{print $2}' > ~/Documents/Linux/s-killMultiPs/pnames.log

 

while read line

do

 

echo "Killing PID: " $line

kill -9 $line

 

done<~/Documents/Linux/s-killMultiPs/pnames.log

 

--


December 31, 2012 at 3:53 AM Flag Quote & Reply

You must login to post.