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 # disabled - we set the CPU limit in the wrapper ./bomb
42 ## set CPU limit, in case the alarm handler will
45 # require BSD::Resource;
46 # BSD::Resource::setrlimit( "RLIMIT_CPU", $timeout, 2 * $timeout )
47 # or die "Cannot set CPU limit: $!\n";
51 # "WARNING: things would go more nicely with the BSD::Resource package\n";
55 # configure signal handlers
60 warn "Alarm handler got called after $timeout seconds\n";
61 warn "Kill now the process group $pgid\n\n";
62 warn "Command: @system\n";
74 or die "system('@system') failed: ?='$?', !='$!'\n";