in reply to Killing a system/exec/`` call if it times out
my $pid = open my $calc, '-|', "$command 2>&1" or die "Pipe failed on open: $!\n"; my $vector = ''; vec($vector,fileno($calc),1) = 1; # Flip bit for pipe unless (select($vector,undef,undef,$timeout)) { # Calculation +is hanging # collect list of spawned processes my @pids = $pid; my $i = -1; push @pids, `ps --ppid $pids[$i] -o pid` =~ /\d+/g while + ++$i < @pids; kill 9, $_ for @pids; die "Calculation call failed to return with $timeout secon +ds\n"; } local $/; # Slurp my $content = <$calc>; close $calc;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Killing a system/exec/`` call if it times out
by Cagao (Monk) on Dec 01, 2011 at 18:51 UTC | |
by ww (Archbishop) on Dec 01, 2011 at 20:24 UTC | |
by Cagao (Monk) on Dec 01, 2011 at 20:56 UTC |