Mercurial > hg > Members > anatofuz > MoarVM
view tools/timeout.pm @ 28:fa930a3213fc
forget minilua
author | anatofuz |
---|---|
date | Sat, 03 Nov 2018 23:24:33 +0900 |
parents | 2cf249471370 |
children |
line wrap: on
line source
package timeout; use strict; use warnings; use Exporter qw(import); our @EXPORT_OK = qw(run_timeout); sub run_timeout { my ($command, $timeout) = @_; my $status; if (my $pid = fork()) { local $SIG{ALRM} = sub { kill 'KILL', $pid; }; alarm $timeout; waitpid $pid, 0; $status = $?; alarm 0; } else { exec @$command; } return $status; } 1;