Jen Spinney wrote:
> Hello all!

Hello,

> 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.

Order of execution is determined by the OS, not by your program.

> It seems that the line (in the child process, second trial)
> my $input = <STDIN>;
> is blocking, but why?

Look carefully at the times displayed, it is not blocking.



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to