How can I kill a Perl system call after a timeout?
Posted
by Fergal
on Stack Overflow
See other posts from Stack Overflow
or by Fergal
Published on 2010-04-21T00:23:18Z
Indexed on
2010/04/21
12:53 UTC
Read the original article
Hit count: 232
perl
|multithreading
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.
© Stack Overflow or respective owner