Excerpt <
        My first attempt used fork() to launch the sub-processes, and
each 
        sub-process would then call exit(0) when complete. However, it 
        appears that exit(0) doesn't release the thread handles: the
manager 
        would fork 64 sub-processes successfully, and then die with
'resource 
        temporarily unavailable' on the 65th. Note that this wasn't a
case of 
        too many concurrent processes: most of the sub-processes would 
        already have exited, so there were never more than about 20
processes 
        active simultaneously.
>

You must REAP your children.

Windows does not support SIG{CHLD} processing, so fake it out by calling
a reaping routine everytime you've completed a connection.

At the top of your code, put this in

use POSIX 'WNOHANG';

Stick this into a convenient routine.

sub ReapChildren {

# this will try to reap all defunct children. 
FORK:
        {
                my $child = waitpid(-1,WNOHANG);
          return if $child <= 0;
                redo FORK;
        }
}

And call it at convenient locations, let's say before you're about to
fork out a new process. ( note you can't do it in the child process )

Or, if you have a trap to look for the "resource temporarily
unavailable" message, call it then.

Hope this helps.


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to