in reply to Re^6: Timeout and kill
in thread Timeout and kill

Oops I posted the wrong version of the code:
sub runFile { local($fileName, $timelimit) = @_; my $child_pid; local $SIG{ALRM} = sub { $didTimeout=1; print OUTPUT "timeout"; print OUTPUT "-", $child_pid; kill $child_pid, 9; }; if ($child_pid = fork ) { # create child waitpid($child_pid, 0); # Wait for child to terminate } elsif (defined $child_pid) { alarm $timelimit; $cmd = "time $solver1 $fileName >> output.txt"; exec ($cmd); alarm 0; exit; } else { # Something terrible has happened, as fork failed die "Cannot fork!\n"; } }
This code times out the function but allows it to still run in the background.