Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to stop a bunch of processes on unix fast.

I can use ps/top, kill.

If the number of processes is very large, I use shell script. Are there other ways, only one or two unix commands can do it well ?

share|improve this question

migrated from stackoverflow.com Oct 27 '11 at 5:16

This question came from our site for professional and enthusiast programmers.

Do you have common name prefix for your processes? – Prince John Wesley Oct 27 '11 at 5:08
The danger here is that when you start killing processes fast, you might kill something you didn't intend to kill. – ObscureRobot Oct 27 '11 at 5:11
telinit 0, or kill -9 1 works well for killing ALL the processes... – lornix Oct 27 '11 at 9:37

My choice is pkill/pgrep

share|improve this answer

Here's a little on-line bash script I use:

ps auxwww | grep -v grep | grep -i $1 | awk '{print $2}' | xargs kill -9

I kills all processes whose name contains the first parameter (case insensitive). The breakdown of each part is:

  • ps auxwww prints all processes with very wide "command" field
  • grep -v grep is there to exclude itself from the killing
  • grep -i $1 matches all lines that contain the first parameter
  • awk '{print $2}' grabs all the process ids
  • xargs kill -9 kills all the selected processes
share|improve this answer
+1 Love a good pipeline, especially one using xargs. – Ray Toal Oct 27 '11 at 5:12
i prefer to use fgrep(no regex) – Prince John Wesley Oct 27 '11 at 5:14
This script is overly complex compared to pkill -9 -f $1. Also, don't advise using signal 9 (KILL). It is a last resort way of stopping a process, not one that should be used routinely. – jlliagre Oct 27 '11 at 5:34

Psdoom is really the only way to kill a process. http://psdoom.sourceforge.net/

share|improve this answer

Very Fast Way to Kill Multiple Processes (without having to write a script)

USAGE: ./autokill.kl.sh <proc-name> => This will give you 5 seconds to change your mind and control-C out of the program.

USAGE: ./autokill.kl.sh <proc-name> now => This will immediately kill all processes matching the string/pattern you specified!!!

MODEL: ./autokill.kl.sh httpd

MODEL: ./autokill.kl.sh httpd now

MODEL: ./autokill.kl.sh httpd view => This will only show you the list of processes matching the pattern you specified.

Script can be directly downloaded here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.