Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Bulletproofing Servers

by perlknight (Pilgrim)
on Jul 19, 2002 at 19:15 UTC ( [id://183390]=perlquestion: print w/replies, xml ) Need Help??

perlknight has asked for the wisdom of the Perl Monks concerning the following question:

All I am reading Network Programming with Perl by Lincoln Stein. I am having trouble on page 443, "Handling HUP and other Signals", here's a snip of the code which I am having trouble with,
sub reap_child { while ( (my $child = waitpid(-1,WHNOHANG)) > 0) { $CHILDREN{$child}->($child) if ref $CHILDREN{$child} eq 'CODE'; delete $CHILDREN{$child}; } }
what's does this line do,  $CHILDREN{$child}->($child) if ref $CHILDREN{$child} eq 'CODE'? Is it saying $CHILDREN{$child} = $child if ref $CHILDREN{$child} eq 'CODE'? What does the value 'CODE' means?
sub kill_children { kill TERM => keys %CHILDREN; sleep while %CHILDREN; }
what does </code>"kill TERM => keys %CHILDREN;"</code> mean? Send a Kill TERM signal to all children pid? Not use to seing "TERM => (value ... values + n". Thanks.

Replies are listed 'Best First'.
Re: Bulletproofing Servers
by jwest (Friar) on Jul 19, 2002 at 19:24 UTC
    To your first question, it means:

    If the value of the hash %CHILDREN at key $child is a reference to a block of 'CODE' (a subroutine), then call that code reference with the value of $child as its first parameter.

    kill TERM => keys %CHILDREN is very much like you suspect. To be clearer, it could be written as:

    kill('TERM', keys(%CHILDREN));

    kill takes a signal as the first parameter, and a list of pids to send the signal to as the rest of its parameters.

    --jwest

    -><- -><- -><- -><- -><-
    All things are Perfect
        To every last Flaw
        And bound in accord
             With Eris's Law
     - HBT; The Book of Advice, 1:7
    
Re: Bulletproofing Servers
by talexb (Chancellor) on Jul 19, 2002 at 19:25 UTC
      if ref $CHILDREN{$child} eq 'CODE';
    I believe this checks to see if the reference type of $CHILDREN{$child} is CODE -- that is, is it a coderef.

      kill TERM => keys %CHILDREN;
    Again, from the reference section of v3 of the Camel, kill takes a SIGNAL and a LIST. The => is a substitue for a comma.

    ps I'm not crazy about the use of ALL CAPS variable names, but am I gonna argue with Lincoln Stein?

    --t. alex

    "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
    --Michael Flanders and Donald Swann

Log In?
Username:
Password:

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

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

    No recent polls found