sub run_with_timeout { my ($cmd, $timeout) = @_; local $SIG{ALRM} = sub { die "Timeout\n"; }; my $out; if (my $pid = open my $pipe, "-|") { eval { alarm $timeout; @$out = <$pipe>; }; my $ok = $@ ne "Timeout\n"; alarm 0; if ($ok) { close $pipe; } else { kill 9, $pid; waitpid $pid, 0; } return $out; } else { exec $cmd; exit; } } my $out = run_with_timeout("$solver $file", $timeout); print defined($out) ? "output of solver:\n@$out" : "timed out"; #### exec "exec $cmd";