system() with timeout
David Cantrell
david at cantrell.org.uk
Thu Apr 16 20:34:16 BST 2009
On Thu, Apr 16, 2009 at 07:44:39PM +0100, David Cantrell wrote:
> On Thu, Apr 16, 2009 at 06:32:08PM +0100, Paul LeoNerd Evans wrote:
> > On Thu, Apr 16, 2009 at 06:18:45PM +0100, David Cantrell wrote:
> > > Anyone recommend a module to give me something like system(@list) but
> > > with a timeout?
> > Does IPC::Run have something suitable? I seem to recall it has quite a
> > lot of interesting things to fiddle with...
> Yes, that looks like exactly what I wanted. Thanks!
But its documentation is utterly impenetrable, so I ended up doing ...
eval {
if(my $pid = fork()) { # parent
local $SIG{ALRM} = sub {
kill 9, $pid; # quit RIGHT FUCKING NOW
die("Child process timed out\n");
};
alarm(5);
waitpid($pid, 0);
alarm(0);
} else {
exec(@blah);
}
};
--
David Cantrell | http://www.cantrell.org.uk/david
Perl: the only language that makes Welsh look acceptable
More information about the london.pm
mailing list