Take the 2-minute tour ×
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.

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
1  
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
add comment

3 Answers 3

My choice is pkill/pgrep

share|improve this answer
add comment

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
8  
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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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