Wednesday, July 05, 2006

How to terminate process by name in UNIX

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

Note that the grep process_name should be the command that you ran. Also note that the commands after 'kill -9' are enclosed in backtiks.

6 comments:

  1. or
    killall -9 process_name
    or
    pkill -9 process_name

    ReplyDelete
  2. Thanks, this is exactly what I needed.

    ReplyDelete
  3. great an efficient, thanks

    ReplyDelete
  4. Great! Thanks a lot

    ReplyDelete
  5. What if the process names are similar and you get results for both? For example semimonthly and monthly. I tried using quotes but I still get results for both instead of one or the other

    ReplyDelete
  6. Another working way:

    ps -el | grep "startct" | awk '{ print $4 }' | xargs kill -9

    ReplyDelete