Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[LINUX:94]



For anyone who's interested:

Here's a quick little script that will kill a process by it's name,
not it's PID...

-----cut here----
ps > /tmp/tempkillfileshouldonlyexistforasec
kill `grep "$1" /tmp/tempkillfileshouldonlyexistforasec | awk '{ print $1 }'`
rm /tmp/tempkillfileshouldonlyexistforasec
----probably should cut here too----

installation:  copy this to some file and put it in your path, I put it in my
/bin directory ('cause that's where kill is) and I decided to
call it killname.
usage:  killname process_name

example:  killname xfishtank

A few notes...

1.  I do it in multiple steps and use the temp file instead of just one large
piped expression because this way it does not include the 'grep' in the ps.
By this I mean if you did "kill `ps -x | grep $1 | awk...'" it would try to
kill all processes with the name $1 in them.  This would incluse the grep
process since it would should up in ps.

2.  This will kill ALL processes with the string $1 in them.  BE CAREFUL!

3.  If you have multiple process with the same name you might be able to kill
the desired one only if you execute it with specific flags.  For example if
you have 2 xterms up one was exected as "xterm -fn 8x16" and the other as
"xterm -fn 7x14" you can kill the one you want (8x16) with:

killname "xterm -fn 8x16"

4.  The $1 in the awk expression is not the same $1 as everywhere else.  Since
the awk expression in in curly braces {} the argument expansion done to the
other $1's are not done.  That $1 mean the first field of the input given to
it.  In this case that is the PID from the output of the grepped ps.



I'm using this script mostly in my .twmrc menus to easily kill things like
variou background animations.  You can use it for whatever you want.


Enjoy,

Rainer


P.S.  I'll post another usefull(less) script soon. :)



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links