in reply to fork(): when parent exits, what happens to child?
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 $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: fork(): when parent exits, what happens to child?
by jethro (Monsignor) on Mar 26, 2010 at 16:39 UTC | |
by 7stud (Deacon) on Mar 26, 2010 at 18:01 UTC | |
by rowdog (Curate) on Mar 28, 2010 at 03:30 UTC | |
|
Re^2: fork(): when parent exits, what happens to child?
by ikegami (Patriarch) on Mar 26, 2010 at 16:25 UTC | |
by 7stud (Deacon) on Mar 26, 2010 at 16:47 UTC | |
by ikegami (Patriarch) on Mar 26, 2010 at 17:20 UTC |