File: timeout.pm

package info (click to toggle)
moarvm 2018.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,196 kB
  • sloc: ansic: 223,172; perl: 7,638; sh: 4,452; makefile: 1,089; python: 568; asm: 8
file content (25 lines) | stat: -rw-r--r-- 432 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;