Hi everybody,
I am back with the same problem, but now I have a short script that demonstrates the issue:
#!perl -w
my $fn = 'fork_test.txt';
my $pid;
if ($pid = fork)
{
print "Hello from ithread 1\n";
open(STDOUT,'>',$fn);
system('ipconfig');
close STDOUT;
waitpid($pid,0);
}
else
{
die 'Couldn\'t fork!' unless defined $pid;
open(READ,'<',$fn);
print "Hello from ithread 2\n";
my $l;
do
{
undef $l; my $i = 0;
while(!defined($l))
{
my $slp = int(($i++ + 9) / 10);
sleep($slp);
$l = <READ>;
};
print $l;
} until($l =~ /Gateway/);
close READ;
}
With Perl 5.6 it works correctly. Both hellos are printed to the screen and you will also see the output of ipconfig to be printed to the screen. But note, that the ipconfig output goes to the file first and then it is read from the file being printed to STDOUT.
With Perl 8.0, this script works incorrectly. Usually, only "Hello from ithread 1" is printed to the screen and everything else goes to the file. However, sometimes "Hello from ithread 2" gets printed to the screen too. It depends on whether the print occurs before the STDOUT gets redirected in the ithread 1. So, it looks like that in spite of file handles being dupped they are shared through some pointer data structure. It really seems that fork is not compatible with the new PerlIO.
What are your thoughts?
--Dave
update (broquaint): changed <small><pre> to <code>
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.