in reply to Re: fork on windows - viewing pseudo-processes
in thread fork on windows - viewing pseudo-processes

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.
  • Comment on Re^2: fork on windows - viewing pseudo-processes

Replies are listed 'Best First'.
Re^3: fork on windows - viewing pseudo-processes
by saintly (Scribe) on Aug 27, 2007 at 22:16 UTC
    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.

      FYI:

      • Win32 never generates SIGCHLD--or any other signal for that matter.
      • the emulation of wait never waits.
      • The emulation of waitpid is terminally broken.

        If you attempt to use it in the non-blocking mode waitpid( -1, WNOHANG) it returns:

        1. -1 when there are no children running
        2. 0 when there are children running (until...)
        3. -1 again when the maximum number of children (63) has been reached!

        The only way waitpid 'works', is when you call it to wait for a specific child.

        If you call it on a child that runs for a long time (or hangs), then everything just stops until that specific child exits or dies.

      The Perl emulation of fork on win32 is so broken as to be almost entirely useless.

      Its only saving grace is that it is responsible, in part at least, for the advent of iThreads. Without those, there would be no useable concurrency possible from Perl on win32.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.