You're viewing a comment by Guhan Iyer and its responses.

March 18, 2010, 18:41

One of my favorites is:

kill -9 `ps -ef | grep search_string | awk '{print $2}'` 

The above will find and kill a process that matches search string.

Comment Responses

s@my Permalink
June 08, 2010, 17:14

Very nice, but you should eliminate the process that contain grep:
kill -9 $(ps -ef|grep search_string|grep -v grep|awk -F " " '{ print $2 }')

Pablo Permalink
June 23, 2010, 01:39

You can do it without grep too:

kill -9 $(ps -ef | awk '/search pattern/ { print $2 }')

And to avoid errors if nothing is found:

ps -ef | awk '/search pattern/ { print $2 }' | xargs -r kill -9

beli Permalink
May 03, 2012, 12:40

instead of "grep -v grep" you can also use "grep [s]earch_string" so the full line would look like:

kill -9 $(ps -ef | grep [s]earch_string | awk -F " " '{ print $2 }')

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "sandbox_195": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.