Linux – How to kill multiple processes

     
22nd July, 2014 by

Here’s a handy command line for killing lots of processes all in one go that match a grep query. The command uses grep to match the processes, awk to grab just the PIDs and then xargs to kill -9 each one. Useful if you have a bunch of misbehaving child processes of a script that keeps generating lots of processes faster than you can kill them all.

ps -ef | grep **the name of process** | grep -v grep | awk ‘{print $2}’ | xargs kill -9

Where **the name of process** is something that will match all the processes you want to kill. Beware though, this command takes no prisoners, anything it matches gets kill -9’d

If you want to make sure you’re going to get it right you can test the grep match using:

ps -ef | grep **the name of process** | grep -v grep

Nick Bryant - Founder

Nick is a 15 year veteran of developing and building successful technology services. He, amongst other things, runs customer service, technical strategy and the cake purchasing rosta at ServerMule. He embraces the joy of learning new technology to the extent any family man can find the time to do.

In 2004 he co-founded what became Australia's largest out of home public ISP, that still services multiple ASX 200 companies and government agencies today.

Follow @NickJBryant
Read More from