RSS

Killing a list of processes

Mon, Apr 16, 2007

System Administration

I’m fighting with a MySQL server at the moment. It’s freshly compiled from source and I’ve followed all of my tried and tested instructions but it won’t start up properly and leaves a load of process hanging around that need killing before I can try starting it again.

pkill wasn’t cutting it so I quickly put this together which kills all of the processes containing the term ‘mysql’ in them when doing a ps ax.

for FOO in `ps ax | grep mysql | grep -v grep | awk '{print $1}'`; do kill -9 $FOO; done

This post was written by:

Bealers - who has written 350 posts on Darren Beale.


Contact the author

2 Comments For This Post

  1. David Goodwin Says:

    1) killall mysqld
    2) killall -9 mysqld

    3) ps auxw | grep [m]ysql | awk ‘{print $2}’ | xargs -r kill
    4) ps auxw | grep [m]ysql | awk ‘{print $2}’ | xargs -r kill -9

    #1 and #2 should work most of the time (just don’t use on Solaris)

    #3 and #4 should catch more processes. The only difference being -9.

    The grep [m]ysql stops grep matching it’s own process (alternatively do grep -v grep in the pipe-chain, as you have).

    David.

  2. Bealers Says:

    Big up to xargs: (http://en.wikipedia.org/wiki/Xargs)

    I’m surprised that’s the first I’ve heard of it. I also like the [] trick, it saves at least 4 characters.

Leave a Reply