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

Greetings brothers,

I'm using ActiveState 5.8.7 on Windows Server 2003 (service pack 1) and have been having trouble getting fork() emulation to behave stably in my scripts. Sometimes it works and sometimes it crashes Perl. I've got the problem narrowed down enough so that the following code will reliably tickle the bug (at least when run from cygwin/bash -- haven't tried the DOS shell yet):

#!c:/Perl/bin/perl.exe sub Fork { my $pid; defined($pid = fork()) or die "Can't fork: $!\n"; if ($pid) {print "in parent ($$).\n"} else {print "in child ($$)\n";exit;} } sub show_block(&$) { my ($block, $message) = @_; $message =~ s/\n*$/\.\.\./o; print $message; my $result = eval { &$block }; $@ ? die "failed: $@\n" : print "done\n"; $result; } Fork(); show_block {Fork()} "testing forking in Windows"; print "done.\n";
The first call to Fork() works as expected printing two lines like:

in parent (2752). in child (-2348)

The wrapped Fork() call then causes a crash. With the code exactly as above I get a popup dialog box that says that basically Perl has crashed (it complains about Perl trying to access a memory location it doesn't have permission to read). If you separate out the the show_block sub into a separate file and use it, then the you also get a message to the shell window: "Bizarre SvTYPE[136] at line <line where the fork() call is> in file Test.pl". (If the script is called Test.pl.)

Has anyone else seen this? Is it worth reporting as a Perl bug to the PTB?

Thanks,

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Update: I've submitted this as a bug in AS's bug database: http://bugs.activestate.com/show_bug.cgi?id=40324

Replies are listed 'Best First'.
Re: Perl Bug in Windows Fork Emulation?
by holli (Abbot) on Aug 08, 2005 at 18:27 UTC
    Sample also crashes as described on Perl 5.8.6 and Windows XP SP2.


    holli, /regexed monk/
Re: Perl Bug in Windows Fork Emulation?
by GrandFather (Saint) on Aug 08, 2005 at 18:37 UTC

    Just run a dozen times under XP sp2 using AS Perl 5.8.7 without problems. Typical result:

    in parent (256). testing forking in Windows...in child (-252) in parent (256). done done. in child (-3100)

    Perl is Huffman encoded by design.
Re: Perl Bug in Windows Fork Emulation?
by xdg (Monsignor) on Aug 08, 2005 at 19:53 UTC

    Crashes as described on Win XP SP1 with ActiveState Perl 5.8.7 build 813. (Run from command line as "perl forktest.pl".)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Perl Bug in Windows Fork Emulation?
by ikegami (Patriarch) on Aug 08, 2005 at 19:10 UTC
    I didn't encounter any problems with ActivePerl v5.6.1 on Win2k:
    in parent (2432). testing forking in Windows...in child (-2576) in parent (2432). done done. in child (-3068)
    I repeated the test numerous times without problem.
Re: Perl Bug in Windows Fork Emulation?
by sk (Curate) on Aug 08, 2005 at 20:06 UTC
    Works just fine for me

    C:\>perl crash in parent (3808). testing forking in Windows...in child (-3932) in parent (3808). done done. in child (-108)
    Info :

    Windows XP SP2 AS Perl: This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail)
Re: Perl Bug in Windows Fork Emulation?
by xdg (Monsignor) on Aug 17, 2005 at 03:58 UTC

    FYI, using an arrow dereference in the eval seems to work without crashing (even if you pass the argument list.)

    my $result = eval { $block->(@_) };

    So it's something in the special magic of &$block that's probably triggering it.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      I know this is reaaaaally old thread, but in case someone line me finds themselves here, I did reproduce the exact same behavior as described by xdg (Crashing and then dereferencing work around) on perl v5.10.1 built for MSWin32-x86-multi-thread However freeing a lot of variables (by undef-ing them) before calling perl fixed it. I shouldn't call it "fix" but rather temporarily avoided. Anyone came across any real solutions?