1

Is it possible to kill all find process with one command?

I do not want to kill each process as kill -9 25295 , kill -9 11994 , etc.. Rather, what I want is a simple way or command that kill all find process (my target is to perfrom this action on linux and solaris machines).

$ ps -ef | grep find 
root 25295 25290   0 08:59:59 pts/1 0:01 find /etc -type f -exec grep -l 100.106.23.152 {} ; -print
root 11994 26144   0 09:04:18 pts/1 0:00 find /etc -type f -exec grep -l 100.106.23.153 {} ; -print
root 25366 25356   0 08:59:59 pts/1 0:01 find /etc -type f -exec grep -l 100.106.23.154 {} ; -print
root 26703 26658   0 09:00:05 pts/1 0:01 find /etc -type f -exec grep -l 100.106.23.155 {} ; -print
3
  • 1
    Having answered some of your questions and looked at may others I think that rather than an Q&A site it's time to talk to your manager about getting some basic education in the tools that you are using.
    – user9517
    Nov 25, 2012 at 15:08
  • @lain this would be so old school! Neat!
    – kubanczyk
    Nov 25, 2012 at 15:21
  • @lain what you think about the solution: fuser -k /tmp/test.sh ? , (for linux and solaris )
    – yael
    Nov 25, 2012 at 15:48

3 Answers 3

5

This will work on both Linux and Solaris and do precisely what you need:

pgrep -f 'find /etc'     # verify the listing before proceeding
pkill -9 -f 'find /etc'

In your situation, avoid killall. If you use it on Linux, sooner or later you will mistake the ssh sessions, run it on Solaris, creating unnecessary risk.

The -f option of pgrep/pkill means to match the entire command line. In case you need to match path of the program or script (/var/tmp/test.sh), this works if you had run it with the entire path. To be precise, you only need to escape the . so you need

pkill -9 -f '/var/tmp/test\.sh'

If you have run the same program as ./test.sh you need to kill it as such. See -f option in ps.

5
  • Someday one of my coworker typed pkill -v foobar , thinking -v would increase verbosity;obviously it was on a production database server... Be careful everyone when you use pkill ;)
    – user130370
    Nov 25, 2012 at 15:24
  • Moreover, f is very close to v on the keyboard :)
    – kubanczyk
    Nov 25, 2012 at 15:29
  • @kubanczyk what about fuser -k /tmp/test.sh - I think is the best solution for linux and solaris - what you think ?
    – yael
    Nov 25, 2012 at 15:46
  • @yael Never used fuser -k, because it does not support regular expressions as patterns. So I don't have any experience to share.
    – kubanczyk
    Nov 25, 2012 at 16:34
  • not sure I try to kill the programs /tmp/test.pl ( was 12 process running on both time ) , and fuser -k killed all (test.pl) process , ,
    – yael
    Nov 26, 2012 at 7:29
3

Use pkill find which is a variant of pgrep (process grep). On Linux, killall find would also work.

1
  • is it possible to kill proccess as script for example - pkill /var/tmp/test.sh ?
    – yael
    Nov 25, 2012 at 15:03
0

Yes, you can use the killall command

killall find 
3
  • 3
    But be very careful if going between Linux and Solaris, because at least on older versions of SunOS that I used, killall literally kills all processes, without the process matching and selection of the Linux version.
    – mattdm
    Nov 25, 2012 at 14:42
  • 1
    As far as I know, this is still the case.
    – Sven
    Nov 25, 2012 at 14:47
  • 1
    As a side note, the behavior is not nearly as funny on Solaris as on AIX. There, killall doesn't kill the current shell, so poor user has no idea how much fun just happened in the background :)
    – kubanczyk
    Nov 25, 2012 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .