Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Kill any process by name UNIX
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.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[8,278 views]  

Kill any process by name | 2 comments | Create New Account
Click here to return to the 'Kill any process by name' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another way
Authored by: rushmoom on Oct 23, '01 01:18:44PM
Here's another way that will also work: ps -auxl | grep emacs | awk '{print $2}' | xargs kill -9 This gets a listing of processes, greps for your search term (in this case emacs), prints the second column (the process id), and then pipes each of the pid's to kill. Note that the above command will attempt to kill *all* emacs processes. You could limit to your user name by inserting another grep: ps -auxl | grep username | grep emacs ....

[ Reply to This | # ]
Another way
Authored by: Pi on Oct 26, '01 10:25:55PM

I use this in aliases.mine:
alias fps ps axu | grep !:1 |grep -v grep

it returns in the case of fps init
root 1 0.0 0.1 1292 248 ?? SLs 0:00.07 /sbin/init
root 2 0.0 0.0 1300 140 ?? SL 0:01.11 /sbin/mach_init

then i can kill it with kill col2num or in extreme cases kill -9 col2num



[ Reply to This | # ]