in reply to avoiding shell escapes with exec()

Regarding your use of fork/exec couldn't you use alarm instead? Soemthing like:
sub cmd_wrapper { my( $cmd ) = @_; my( $rc , $out ); eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 15; $out = (`$cmd`)[0]; # Get first line of output $rc = $?; alarm 0; }; if( $@ ) { die "Eval failed for $cmd but not because of alarm" if $@ ne " +alarm\n"; # Propogate unexpected errors die "Eval failed for $cmd because alarm timed out"; } die "Return code undefined for $cmd" unless defined $rc; return $rc, $out if wantarray; return $rc; }

Replies are listed 'Best First'.
Re^2: avoiding shell escapes with exec()
by chunter (Initiate) on Jun 27, 2007 at 18:46 UTC
    I did try using alarm, and that works great for keeping the parent process from hanging, but it does not help with keeping track of the child pids that hang, which is the main issue I have
      I was under the impression that the only reason you were using the fork was to help deal with the hanging issue. I take it you need to do some batch processing instead?