I get similar behavior on Win2000. The fork appears to mess with the file handle:
#!/usr/bin/perl use strict; use warnings; my $x=0; while (my $computer=<DATA>) { print "computer: [$computer]"; chomp($computer); $x++; my $pid = fork(); if ($pid) { print "Parent $$ got PID $pid from fork($$ $computer)\n"; sleep(1); }else { print "\t$$ $computer\n"; exit(0); } if($x > 4) { do { $pid=wait() } while ($pid != -1); $x=0; } } my $pid; do { $pid=wait() } while ($pid != -1); print "wait() ed until $pid was returned.\n"; close(DATA); __DATA__ Computer1 Computer2 Computer3 # Output computer: [Computer1 ]Parent 1782987 got PID -1853375 from fork(1782987 Computer1) -1853375 Computer1 computer: [ ]Parent 1782987 got PID -1852747 from fork(1782987 ) -1852747 computer: [Computer2 ]Parent 1782987 got PID -1805143 from fork(1782987 Computer2) -1805143 Computer2 computer: [ ]Parent 1782987 got PID -1804643 from fork(1782987 ) -1804643 computer: [Computer3 ]Parent 1782987 got PID -1898099 from fork(1782987 Computer3) -1898099 Computer3 wait() ed until -1 was returned.
The problem goes away if you slurp the input first, like:
for my $computer (<DATA>) { ...

In reply to Re: Win32 fork() "problem" by runrig
in thread Win32 fork() "problem" by maa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.