Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: Killer

by tye (Cardinal)
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).


Comment on RE: Killer
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://26206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-09-01 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls