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";
9 use BSD::Resource qw/setrlimit/;
19 binmode \*STDOUT, ":utf8";
20 binmode \*STDERR, ":utf8";
24 usage: $0 [ options ] command args ....
26 --debug=0..3 debug option, default: $debug
27 --timeout=1..N timeout in seconds, default: $timeout
34 "timeout=f" => \$timeout,
40 die usage if !@system;
42 # set CPU limit, in case the alarm handler will
44 setrlimit(RLIMIT_CPU, $timeout, 2*$timeout) or die "Cannot set CPU limit: $!\n";
47 # use fork/exec instead system()
50 die "fork() failed: $!" unless defined $pid;
55 exec(@system) or die "exec @system: $!\n";