http://www.perlmonks.org?node_id=989768


in reply to pipe fork win32

Try this:

use strict; use warnings; my ($child, $parent); pipe($child, $parent) or die; my $pid = fork(); die "fork() failed: $!" unless defined $pid; if ($pid) { close $child; } else { close $parent; print "child waiting\n"; my $read; read($child, $read, 1); print "child exiting\n"; exit(0); } print $parent "exit now\r\n\r" x 373; print "parent going to wait\n"; waitpid($pid, 0);

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: pipe fork win32
by bulk88 (Priest) on Aug 26, 2012 at 02:23 UTC
    If I change 373 in "print $parent "exit now\r\n\r" x 373;" to 745 (744 hangs) it works.
    C:\Documents and Settings\Owner\Desktop>perl -e "print (length(\"exit +now\r\n\r\ " x 745).\"\n\");" 8195
    I guess is somewhat explained by the hung C callstack of the child of my first script.
    ntdll.dll!_KiFastSystemCallRet@0() ntdll.dll!_NtReadFile@36() + 0xc kernel32.dll!_ReadFile@20() + 0x67 > msvcr71.dll!_read_lk(int fh=3, void * buf=0x00963fec, unsigned in +t cnt=8192) Line 154 + 0x15 C msvcr71.dll!_read(int fh=3, void * buf=0x00963fec, unsigned int c +nt=8192) Line 75 + 0xc C perl517.dll!win32_read(int fd=3, void * buf=0x00963fec, unsigned +int cnt=8192) Line 3209 + 0x12 C perl517.dll!PerlLIORead(IPerlLIO * piPerl=0x00346654, int handle= +3, void * buffer=0x00963fec, unsigned int count=8192) Line 1033 + 0x +11 C++ perl517.dll!PerlIOUnix_read(interpreter * my_perl=0x0093502c, _Pe +rlIO * * f=0x00935e8c, void * vbuf=0x00963fec, unsigned int count=819 +2) Line 2789 + 0x22 C perl517.dll!Perl_PerlIO_read(interpreter * my_perl=0x0093502c, _P +erlIO * * f=0x00935e8c, void * vbuf=0x00963fec, unsigned int count=81 +92) Line 1679 + 0x3e C perl517.dll!PerlIOBuf_fill(interpreter * my_perl=0x0093502c, _Per +lIO * * f=0x00935aa4) Line 4033 + 0x1b C perl517.dll!Perl_PerlIO_fill(interpreter * my_perl=0x0093502c, _P +erlIO * * f=0x00935aa4) Line 1776 + 0x36 C perl517.dll!PerlIOBase_read(interpreter * my_perl=0x0093502c, _Pe +rlIO * * f=0x00935aa4, void * vbuf=0x0095b49c, unsigned int count=1) + Line 2170 + 0xd C perl517.dll!PerlIOBuf_read(interpreter * my_perl=0x0093502c, _Per +lIO * * f=0x00935aa4, void * vbuf=0x0095b49c, unsigned int count=1) +Line 4054 + 0x15 C perl517.dll!Perl_PerlIO_read(interpreter * my_perl=0x0093502c, _P +erlIO * * f=0x00935aa4, void * vbuf=0x0095b49c, unsigned int count=1) + Line 1679 + 0x3e C perl517.dll!Perl_pp_sysread(interpreter * my_perl=0x0093502c) Li +ne 1775 + 0x18 C perl517.dll!Perl_runops_debug(interpreter * my_perl=0x0093502c) +Line 2126 + 0xd C perl517.dll!win32_start_child(void * arg=0x0093502c) Line 1742 + + 0xd C++ kernel32.dll!_BaseThreadStart@8() + 0x37
    0x2000/8192 was passed as the read amount to ReadFile. Does anyone know what should have happened on Windows? What happens on Unix? 8192 read also? or it will still succeed for POSIX reasons? is the 8192 read length a bug or correct?
      If I change 373 in "print $parent "exit now\r\n\r" x 373;" to 745 (744 hangs) it works.

      Hm. I used 373 because that is the lowest value on my system that worked (373 * 11 > 4096), so my system (Vista64) is using a 4096 byte buffer.

      I thought all Windows systems used that size. I wonder why yours is using 8k? What version of windows are you running? Are you using a home-built version of Perl? Did you tweak the value?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

      The start of some sanity?

        For performance reasons, Perl's buffer was changed from 4K to 8K in 5.14.0. It was also made configurable at build time at the same time.