On 03/13/2016 02:14 PM, Peter Scott wrote:
> On Sat, 12 Mar 2016 18:44:18 +0200, Lars Noodén wrote:
[snip]
>> What modification can prevent zombies yet allow multiple concurrent
>> clients to attach?
> 
> You need the WNOHANG option on your wait() to make it nonblocking.

Thanks.  I've been exploring that and seem to have found out how to make
it work in my case where the program forks children on an ongoing basis
and the parent needs to stay running.

Prior to handling SIGCHLD myself, the $socket->accept() loop was the
outer loop, but returning from the subroutine always caused the loop to
exit.  What causes that and how can it be prevented?  What I use right
now is another loop around the first loop, but that seems awkward:

 sub trap_chld {
     waitpid( -1,WNOHANG );
     return( 1 );
 }

 $SIG{CHLD} = \&trap_chld;

 ...

 while ( 1 ) {
     while ( my $client_socket = $socket->accept() ) {
         ...
     }
 }
 exit( 0 );

Regards,
/Lars

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to