Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

RE: Killer

by tye (Sage)
on Aug 04, 2000 at 19:26 UTC ( #26206=note: print w/replies, xml ) Need Help??

in reply to Killer

Using /bin/grep, awk, and /bin/kill inside Perl! Blasphemy!!! Friar, where is the hot oil?? ;)

#!/usr/bin/perl -w use strict; die "Usage: $0 regex\n" unless 1 == @ARGV; for my $proc ( map {(split(' '))[1]} grep /$ARGV[0]/, `ps -ef` ) { if( ! kill(-9,$proc) ) { warn "Can't kill PID $proc: $!\n"; } else { print "Killed PID $proc.\n"; } }

And that still leaves much room for improvement (and I didn't test this either, sorry).

Replies are listed 'Best First'.
RE: RE: Killer
by merlyn (Sage) on Aug 05, 2000 at 01:51 UTC
    I'm never sure why people bring out the flamethrower to light a candle. I have a little rant on "please stop using kill -9" that I post to comp.unix.questions when I see postings like this. Basically, -9 is harmful because it doesn't give the process a chance to clean up. Try a 2, a 1, and a 15, waiting 1 second each time. If all those fail, then a 9.

    Also, -9 is "kill 9 to everyone in the process group". You want +9, certainly!

    -- Randal L. Schwartz, Perl hacker

      Actually, that is one of my pet peeves, too. It has been a long time since I've seen someone type "kill" at a Unix shell prompt, so I've become desensitize (too much Win32 -- also part of why I didn't test this).

      Also, thanks for catching the too-literal translation of /bin/kill to kill().

              -- tye (but my friends call me "Tye")
      Merlyn has got your number ergowolf.

      -9 like using Nitro. Fun, but not productive.

      I like to use the applications normal shutdown procedure, if possible and if it has one

      Then kill -15 - "please shut down now little process" then kill -2 - "come on and shut down now." then and only then kill -9 "die, die vile process!!"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://26206]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2017-11-19 15:01 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (281 votes). Check out past polls.