F
Franklin H.
As a test case for forking and having each fork write to a file I did
the following:
### begin foo.pl:
#!perl
use strict;
my $trials = 2;
foreach my $i (1 .. $trials) {
unless (fork) {
# child
my $outfile = "${i}.txt";
my $cmd = "perl bar.pl $i |";
open (CMD, $cmd) or die $!;
open (FILE, ">$outfile") or die $!;
while (<CMD>) {
print FILE $_;
}
warn "$i cmd finished\n";
close FILE;
close CMD;
exit;
}
}
exit;
#### end foo.pl
### begin bar.pl:
#!perl
print "$ARGV[0]\n";
close STDOUT;
warn "*** $ARGV[0] program completed\n";
exit;
### end bar.pl
The stderr I'm getting is:
*** 1 program completed
*** 2 program completed
*** 3 program completed
3 cmd finished
1 cmd finished
but I'm never seeing one of the processes actally complete in the
cakker script (foo.pl). This occurs for any value of $trials > 1.
Any idea what the heck could be wrong?
the following:
### begin foo.pl:
#!perl
use strict;
my $trials = 2;
foreach my $i (1 .. $trials) {
unless (fork) {
# child
my $outfile = "${i}.txt";
my $cmd = "perl bar.pl $i |";
open (CMD, $cmd) or die $!;
open (FILE, ">$outfile") or die $!;
while (<CMD>) {
print FILE $_;
}
warn "$i cmd finished\n";
close FILE;
close CMD;
exit;
}
}
exit;
#### end foo.pl
### begin bar.pl:
#!perl
print "$ARGV[0]\n";
close STDOUT;
warn "*** $ARGV[0] program completed\n";
exit;
### end bar.pl
The stderr I'm getting is:
*** 1 program completed
*** 2 program completed
*** 3 program completed
3 cmd finished
1 cmd finished
but I'm never seeing one of the processes actally complete in the
cakker script (foo.pl). This occurs for any value of $trials > 1.
Any idea what the heck could be wrong?