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

Hello again dear monks,
Screaming for help twice in a day, what can I say, I hate Mondays...
So here's the thing. I created a server which receives messages and creates child processes to handle these messages. Everything went fine till today, when I made a simple test, sending the same message 100 times. Well, my server creates exactly 64 child processes and then starts returning undef (as far as I know, ths means that fork() has failed). I konw that there are some limits concerning the number of pseudo-processes running at the same time, because they really make part of the same process and stuff. The thing is I don't need these 100 processes to run concurently. That's why i am exiting the child process (with exit 0) when its job is finished. So I don't have 64 processes running in parallel, I have only 2 or 3, depending on the time of exit. But even if I serialize the process and wait for the child to exit before creating a new child, I get this 64. For what I see, even after exit, the child is still counted as alive. That's why I want to vizualize all the pseudo-processes running at a given time. As 64 is not 42, I suppose there has to be a logical explanation for this and I beg you to save my stormy Monday.
Thanks.
PS: Sorry I didn't put any code in but the application contains several packages and it is really difficult to assemble it as a simple example.
  • Comment on fork on windows - viewing pseudo-processes

Replies are listed 'Best First'.
Re: fork on windows - viewing pseudo-processes
by moritz (Cardinal) on Aug 27, 2007 at 16:24 UTC
      Hello moritz,
      I don't wait because I would block the server until the child exits. As for the diagnostic, I get
      Resource temporarily unavailable
      Thanks for the idea with Parallel::ForkManager, I will look over it right after posting this. I hope it works on Windows.
        Moritz doesn't mean to use the 'wait' command right after you fork (which would block till your child was done). The typical usage for wait is to execute it in response to a SIGCHLD signal:
        sub reaper { my $deadChildPID = wait; print "Reaped child $deadChildPID\n"; } $SIG{'CHLD'} = \&reaper; # ..... some time later ..... if( $pid = fork() ) { # begin FORK section }
        In any event, your dead children are waiting around as zombies for you to acknowledge their death. The zombies are preventing you from forking off more children. If you don't care about acknowledging their death, you can use something like this:
        $SIG{CHLD}='IGNORE';
        before you fork off any processes. This should work in Windows (and UNIX) to automatically reap your children without making a handler function.