Kill any process by name

Oct 22, '01 06:26:27PM

Contributed by: Anonymous

To kill an evil process you have to find the process ID through top or ps, in short it's a long process.

I devised a way around this using embedded commands. Type the following into the terminal to get a kill that works on process names:

alias newkill 'kill `top -l1 | grep -i \!* | cut -c1-5`'
The command outouts a log version of top that gets passed to grep that searches for the string you enter, cuts the first 5 characters, the PID and finally passes that to the kill command.

Be careful, top doesn't always display the entire name of the process and it will match all instances of the string and kill them.

[Editor's note: Definitely use some care here! Others simply use a modified "grep" and "kill" combo to accomplish the same thing. If you want this to be permanent, it will need to go into your aliases.mine file.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2001102218262723