Discordanian has asked for the wisdom of the Perl Monks concerning the following question:
The contents of smoke.sh:#! /usr/bin/perl -w -I. use strict; ###################################################################### +########## # DATA ###################################################################### +########## # Standard Modules use Data::Dumper; my $pid = ''; + # For forking. my $templog = ''; my @smokearr = ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'); # Run ls over and over. #--------------------------------------------------------------------- +- for ( my $index = 0 ; $smokearr[$index] ; $index++ ) { $templog = "./$smokearr[$index].log"; my $syscmd = "./smoke.sh > $templog 2>&1"; fail("fatal: cannot fork: $!") unless defined( $pid = fork() ) +; # Run sort as a child and exit if ( !$pid ) { print STDERR "Running [$syscmd] ($$)\n"; system($syscmd) == 0 or print STDERR "fatal: system \"$syscmd\" failed: +$? See log $templog\n"; exit 0; } } # Wait for the child processes to finish. #---------------------------------------- wait; # Check each log file for smoke.pl #--------------------------------------------------------------------- +--- for ( my $index = 0 ; $smokearr[$index] ; $index++ ) { $templog = "./$smokearr[$index].log"; my $syscmd = "grep smoke.pl $templog"; print STDERR "Running [$syscmd] ($$)\n"; system($syscmd) == 0 or print STDERR "fatal: system \"$syscmd\" failed: $? See l +og $templog\n"; } exit 0;
#!/bin/sh cat smoke.txt |sort | uniq -c
As you can see, smoke.sh is trivial, but it has pipes.
The contents of smoke.txt is just a long text listing with smoke.pl being a line in there.
When I run my app, smoke.sh runs, wait gets the returned children but I get several failures in the log.
My theory is that smoke.sh returns before the piped grandchildren (I originally just had a cat without the pipes, but the error didn't occur). I also get the error if I put $syscmd = "cat smoke.txt |sort |uniq -c > $templog 2>&1"; directly.
So how can I get around this? I do a fork call 11 times writing to 11 log files and then I'm grepping those log files for a certain result and I get errors and this is presumably because the app I'm calling forks a writing thread.
$ uname -a AIX nevd1 1 5 000DA5AF4C00 unknown unknown AIX $ perl --version This is perl, v5.6.0 built for aix
Any and all help is greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fork Wait and probably grandchildren
by polettix (Vicar) on Apr 05, 2005 at 15:39 UTC | |
by Discordanian (Initiate) on Apr 05, 2005 at 18:00 UTC | |
by tlm (Prior) on Apr 05, 2005 at 17:19 UTC | |
by polettix (Vicar) on Apr 05, 2005 at 17:52 UTC | |
by tlm (Prior) on Apr 05, 2005 at 18:07 UTC | |
by RazorbladeBidet (Friar) on Apr 05, 2005 at 17:24 UTC | |
by tlm (Prior) on Apr 05, 2005 at 17:33 UTC | |
by RazorbladeBidet (Friar) on Apr 05, 2005 at 17:40 UTC | |
|
Re: Fork Wait and probably grandchildren
by RazorbladeBidet (Friar) on Apr 05, 2005 at 17:00 UTC | |
|
Re: Fork Wait and probably grandchildren
by tlm (Prior) on Apr 05, 2005 at 16:34 UTC |