2 # Copyright (c) 2014 IndexData ApS. http://indexdata.com
4 # bomb.pl - wrapper to stop a process after N seconds
8 use POSIX ":sys_wait_h";
18 binmode \*STDOUT, ":utf8";
19 binmode \*STDERR, ":utf8";
23 usage: $0 [ options ] command args ....
25 --debug=0..3 debug option, default: $debug
26 --timeout=1..N timeout in seconds, default: $timeout
33 "timeout=f" => \$timeout,
39 die usage if !@system;
41 # set CPU limit, in case the alarm handler will
44 require BSD::Resource;
45 BSD::Resource::setrlimit("RLIMIT_CPU", $timeout, 2*$timeout) or die "Cannot set CPU limit: $!\n";
48 warn "Please install the package BSD::Resource!\n\n$@\n";
53 # use fork/exec instead system()
56 die "fork() failed: $!" unless defined $pid;
61 exec(@system) or die "exec @system: $!\n";