2 # Copyright (c) 2014 Index Data 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 )
46 or die "Cannot set CPU limit: $!\n";
50 "WARNING: things would go more nicely with the BSD::Resource package\n";
54 # configure signal handlers
59 warn "Alarm handler got called after $timeout seconds\n";
60 warn "Kill now the process group...\n\n";
72 or die "system('@system') failed: ?='$?', !='$!', ^E='$^E', ?='$?'";