It may not be the best way because I've just been trying anything I can find. The code will timeout the function, but not kill it. Any suggestions? Help would be greatly appreciated. I've tried everything I can find online without success. Thanks!sub runFile2 { local($fileName, $timeout) = @_; my $child_pid; local $SIG{ALRM} = sub { $didTimeout=1; print OUTPUT "timeout"; print OUTPUT "-", $child_pid; kill 9, $child_pid; }; if ($child_pid = fork ) { # create child $didTimeout=0; alarm $timeout; $start=gettimeofday(); waitpid($child_pid, 0); # Wait for child to terminate alarm 0; $end=gettimeofday(); if($didTimeout==0) { print OUTPUT $end - $start; } else { kill 9, $child_pid; } } elsif (defined $child_pid) { $cmd = "$solver1 $fileName >> output.txt"; exec ($cmd); exit; } else { # Something terrible has happened, as fork failed die "Cannot fork!\n"; } }
In reply to Re^6: Timeout and kill
by nelson64
in thread Timeout and kill
by nelson64
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |