Hi,
Thanks for the responses. The os is mac osx 10.4.11.
It doesn't seem like a buffering problem to me. If the child actually finished executing, then wouldn't the close() execute on the output file handle, thus flushing the buffer to the file?
Here is what happens when I turn on autoflush for the output filehandle:
use strict; use warnings; use 5.010; my $child_pid = fork; $| = 1; if (!defined $child_pid) { say "**My error**: couldn't fork: $!"; } if ($child_pid) { #then in parent say "in parent..."; sleep 1; } else { #then in child open my $OUTFILE, '>', 'data1.txt' or die "**My error: couldn't open data1.txt: $!"; my $old = select $OUTFILE; $| = 1; select $old; for (1 .. 10) { say $OUTFILE $_; sleep 2; } close $OUTFILE; }
--output:-- $ perl 1perl.pl in parent... $ cat data1.txt 1 2 $
In reply to Re: fork(): when parent exits, what happens to child?
by 7stud
in thread fork(): when parent exits, what happens to child?
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |