Tuesday, 27 November 2012

Killing all processes that match a given string

If you want to kill all processes matching a given executable, you can easily use killall:

killall -9 my_executable

But what if you don't want to kill processes based on an executable name, but rather on some argument name, or something else? That is, all processes that match some string?

You can. Here is the trick:

kill -9 $(ps aux | grep -v grep | grep my_process | awk '{print $2}') 

(originally from here)