Killing specific processes with ps, grep, awk and xargs

Often when you work with Linux you need to kill a bunch of processes matching a certain pattern. This could be accomplished using ps, grep, awk and xargs like this:

ps -aux |grep php-fpm |grep -v grep | awk '{print $2}' | xargs kill

If the process won’t die you could add -9 to kill which can’t be blocked by anything. Of course you need to own the processes you try to kill (or use sudo).

References:
Article on commandlinefu.com

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.