sub _timedFork2 { my ($command, $time) = @_; my $pid; my @resp2; local $SIG{ALRM} = sub {kill 15, $pid or die "kill: $!"; die 'Timeout!'; }; eval { $pid = fork(); unless (defined $pid) { die "Fork failed: $!"; } unless ($pid) { @resp2 = `$command`; } alarm $time; waitpid $pid => 0; }; if ($@ and $@ !~ m/Timeout!/i) { die $@; } return @resp2; }