How can I kill a Perl system call after a timeout?
- by Fergal
I've got a Perl script I'm using for running a file processing tool which is started using backticks. The problem is that occasionally the tool hangs and It needs to be killed in order for the rest of the files to be processed.
Whats the best way best way to apply a timeout after which the parent script will kill the hung process?
At the moment I'm using:
foreach $file (@FILES) {
$runResult = `mytool $file >> $file.log`;
}
But when mytool hangs after n seconds I'd like to be able to kill it and continue to the next file.