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

Re: ppk

by merlyn (Sage)
on Apr 18, 2005 at 02:16 UTC ( [id://448716]=note: print w/replies, xml ) Need Help??


in reply to ppk

Two red flags, and some yellow flags, as follows:

First red flag:

$b =~m/^\s*\w+\s+(\d+)\s+/o; my $b_pid = $1;
This code will get an incorrect $1 if the regex doesn't match. Never never Never look at $1 unless you've also tested the match.

Oh, and that applies a few lines later too. At least you're consistently wrong.

Second red flag:

my @args = ("kill", "-9", $2);
Never never never use kill -9 on a process, unless that process has resisted prior attempts to die via kill 1, 2, and 15.

First yellow flag, back to the earlier code snippet:

m/^\s*\w+\s+(\d+)\s+/o
What's the /o doing there? {insert cricket chirp sound effects} Right, nothing. Doesn't hurt it, but it absolutely doesn't help it either. In fact, you should remove it universally in this program (I just noticed it earlier too).

Second yellow flag... that sort screams for a Schwartzian Transform.

Third yellow flag: Perl has a kill function. Why not use it instead of system'ing out?

Conclusion: other than the bit about the Schwartzian Transform, the knowledge you are missing is contained within Learning Perl, which suggests that you read that book very soon.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: ppk
by jplindstrom (Monsignor) on Apr 19, 2005 at 11:44 UTC
    Never never never use kill -9 on a process, unless that process has resisted prior attempts to die via kill 1, 2, and 15.

    Is that general advice for all processes, or is it only for programs that you don't know, that haven't failed to die properly earlier, etc?

    I.e. if I have a program whose processes consistently fail to die properly, should I still kill it with 1, 2, and 15 before 9?

    /J

      if I have a program whose processes consistently fail to die properly, should I still kill it with 1, 2, and 15 before 9
      If you have a program like that, you should rewrite it! {grin}

      But yes, that's the applicable rule. "kill -9" is always the "last resort" kill.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Ok. Let me rephrase my question:

        Why?

        (I'm trying to acquire deep technical knowledge here, not cargo cult ;)

        /J

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found