1819791 Members
3282 Online
109607 Solutions
New Discussion юеВ

kill by process name

 
SOLVED
Go to solution
Brent W. Moll
Advisor

kill by process name

I need a script which will kill a process by name, rather by number.

Does anyone have one ?

Thank you :)
10 REPLIES 10
G. Vrijhoeven
Honored Contributor
Solution

Re: kill by process name

Hi,

#!/usr/bin/ksh
PROC=$1
for PID in `ps -eaf | grep -v grep | grep $PID | awk '{ print $2}'`
do
kill $PID
done
G. Vrijhoeven
Honored Contributor

Re: kill by process name

sorrie:


#!/usr/bin/ksh
PROC=$1
for PID in `ps -eaf | grep -v grep | grep $PROC | awk '{ print $2}'`
do
kill $PID
done

HTH,

Gideon
Steven E. Protter
Exalted Contributor

Re: kill by process name

attaching a script called gkill.

I typed it out of a text book. It is powerful and dangerous. I added protection against slamming processes owned by root.

See attachment

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor

Re: kill by process name

Brent,

This is, indeed, very dangerous. You need to be extremely careful with your grep command to make sure you get exactly the process you want. I would suggest display the output of the grep for confirmation before killing anything!


Pete

Pete
Oliver Schmitz
Regular Advisor

Re: kill by process name

I have nothing ready but here a raw scetch what i can imagine so quick:

test=`ps -ef |gerp 'process name'`
echo $test
Search in this string for the pid and kill it.

Maybe this helps.

Best regards,
Oliver
Oliver Schmitz
Oliver Schmitz
Regular Advisor

Re: kill by process name

O.k. to late.

Regards,

Oliver
Oliver Schmitz
Pete Randall
Outstanding Contributor

Re: kill by process name

Brent,

(In case you do come back to this).

It took a bit of searching but I found an excellent thread on this very subject. Pay particular attention to the responses of JRF and Bill H.


Pete

Pete
Kent Ostby
Honored Contributor

Re: kill by process name

touch .killit
rm .killit*
echo "TRAN" $1 > .killit1
ps -ef | cut -c10-15,48-80 >> .killit1
awk '/^TRAN/{matchme=$2;next;}$2==matchme{print "kill ",$1};' .killit1 > .killit
2
chmod +x .killit2
./.killit2

Make sure on word wrap. Right now there is a "2" showing up on a seperate line which should really be the end of ".killit2".

Best regards,

Kent Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Pete Randall
Outstanding Contributor

Re: kill by process name

Pete Randall
Outstanding Contributor

Re: kill by process name

Oh, and Clay makes some good points too!


Pete

Pete