Hello all!
I've come to a point where I really need to start understanding
forking, threaded, select, and all that stuff. I created a test
script to play around with and it's doing what I'd expect, except for
one bit. My test script:
use strict;
use warnings;
print "First Trial:\n\n";
if (open(CHILD, "|-"))
{
print "parent starts: ", (scalar localtime),"\n";
sleep 5;
print "parent ends: ", (scalar localtime),"\n";
}
else
{
my $time = scalar localtime;
print "child starts: $time\n";
exit;
}
print "\nSecond Trial:\n\n";
if (open(CHILD, "|-"))
{
print "parent starts: ", (scalar localtime),"\n";
print CHILD "printing to child\n";
sleep 5;
print "parent ends: ", (scalar localtime),"\n";
}
else
{
my $time = scalar localtime;
my $input = <STDIN>;
print "child starts: $time\n";
exit;
}
__END__
My output looks like this:
First Trial:
parent starts: Wed Nov 8 13:45:14 2006
child starts: Wed Nov 8 13:45:14 2006
parent ends: Wed Nov 8 13:45:19 2006
Second Trial:
parent starts: Wed Nov 8 13:45:19 2006
parent ends: Wed Nov 8 13:45:24 2006
child starts: Wed Nov 8 13:45:19 2006
I expected the first trial print statements to execute in the same
order as the second trial print statements, but the child print
statements don't do execute until after the parent process is over.
It seems that the line (in the child process, second trial)
my $input = <STDIN>;
is blocking, but why? I would understand if I had a while (<>) loop
or something because that would be just sitting there waiting for
input from the parent process. But <STDIN> is a one-shot deal that
just looks for the input line delimiter, right? Once it hits "\n"
shouldn't it just move on?
Thanks to anyone who can offer any insight or point me in the right direction,
Jen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>