Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://26206]
help
Chatterbox?
[LanX]: It seems that PHP's official docs use "closure" and "anonymous function" interchangeably, even though their closures don't capture surrounding state without using the 'use' language construct.
LanX explains much cargo bla ...
[Eily]: what? I thought PHP was known for its reliable and consistent behaviour and documentation!
[LanX]: ... and a lot of pseudo Perl experts
[Eily]: though honestly, I'm sure I have seen people use closure to mean anonysub for perl as well
[stonecolddevin]: good morning friends
[LanX]: yes, mainly pseudo Perl experts
[Eily]: good morning stonecolddevin
LanX has to go/

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2018-02-23 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (304 votes). Check out past polls.

    Notices?