2007-02-17

Kill Process by Name on UNIX

Here is a ksh script to kill processes by name.
Usage: kill processName

---------------- cut here ---------------------
#!/usr/bin/ksh

str="$1"

ps -ef grep "$str" {
while read aline;do
cmd=`echo $aline awk '{ print $9 }'`
if [ [ $cmd = $0 ] ]; then
continue
fi

cmd=`echo $aline awk '{ print $8 " " $9 " " $10 }'`
if [ [ $cmd = "grep" ] ]; then
continue
fi

cmd2=`echo $cmd grep "$str"`
if [ [ $cmd2 = "" ] ]; then
continue
fi

print "$aline"
pid=`echo $aline awk '{ print $2 }'`
print "kill pid = $pid"
kill -9 $pid
done
}

---------------- cut here -----------------------

0 Comments:

Post a Comment

<< Home