Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Re: Have children maintain themselves or main script maintain children.

by ncw (Friar)
on May 11, 2001 at 21:18 UTC ( [id://79776]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Have children maintain themselves or main script maintain children.
in thread Have children maintain themselves or main script maintain children.

There are several disadvantages to installing a SIGCHLD handler

  • Signals aren't reliable so you may not get one for every child expiry. Using waitpid in a loop will help here.
  • You can get SIGCHLDs from your children when they haven't died (eg your child gets sent a SIGSTOP - the parent will get a SIGCHLD)
  • You can get SIGCHLDs from perl operations like open "|.." and backticks if you are unlucky which can confuse things.
  • Unreliable signals are evil!

Some of the examples in The Perl Cookbook have the correct waitpid in a loop in the SIGCHLD handler, but some don't (for instance the section on a preforking daemon).

Personally I would ignore SIGCHLD and make the parent wait() for the children to die. It will be nicely blocked (ie not using any excess CPU) until it needs to do something (ie make more children).

  • Comment on Re: Re: Re: Have children maintain themselves or main script maintain children.

Replies are listed 'Best First'.
Re: Re: Re: Re: Have children maintain themselves or main script maintain children.
by the_0ne (Pilgrim) on May 11, 2001 at 21:50 UTC
    Thanks for the explanation. We HAVE run into your first bulletpoint. We had some children come back that gave us the pid instead of 0 or -1 and had to work around that. So, I can understand your explanation there.

    for instance the section on a preforking daemon

    I'm almost positive (I don't have the book here with me today.) that the preforking daemon is the major example we used and you're right, it does not have the waitpid. We got lucky and found that in a post on good old PM.

    Personally I would ignore SIGCHLD and make the parent wait() for the children to die. It will be nicely blocked (ie not using any excess CPU) until it needs to do something (ie make more children).

    gr0k and I were just talking about that. I think my weekend project has just shown up. :)

    Thanks to everybody that has helped out with this node.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-16 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found