Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: IO::Socket Not responding after period of time and traffic!

by rowdog (Curate)
on Aug 15, 2010 at 13:01 UTC ( #855141=note: print w/ replies, xml ) Need Help??


in reply to IO::Socket Not responding after period of time and traffic!

I believe Corion is on the right track. You have

1 until (-1 == waitpid(-1, WNOHANG));
While perlipc uses
while (($child = waitpid(-1,WNOHANG)) > 0) { $Kid_Status{$child} = $?; }

The key difference being that your reaper continuously loops when waitpid returns 0, which means the a child is still running (depending on the OS). Why would that matter? If you have 2 kids running and one exits, your signal handler will waitpid for the finished child and then loop to waitpid again, since the second child is running, the return is zero so you loop again, and again, and again.

I know that the details of signal handling vary a lot across different OSes so there may be a perfectly valid reason to be using -1, but I can't see why from here.

Update: It's a child, not the child.


Comment on Re: IO::Socket Not responding after period of time and traffic!
Select or Download Code
Re^2: IO::Socket Not responding after period of time and traffic!
by Corion (Pope) on Aug 15, 2010 at 13:08 UTC

    Actually, wait returns the PID of the just reaped child, and under the Windows fork emulation, emulated forked children get negative PIDs, so a check for equality to -1 sounds saner than checking for >0.

      Well, okay, that's a good point but I'm not crazy enough to want to deal with fork and Windows (use threads;)

      My point is that most UNIX like OSes treat a return of zero from waitpid with the WNOHANG option as a special case that says "there are no stopped, continued or exited children". If you idle loop waiting for your children to exit, you won't be getting out of the signal handler often enough to handle new connections. Just testing for -1 isn't enough.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-12-27 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls