2 # Copyright (c) 2014 IndexData ApS. http://indexdata.com
4 # bomb.pl - wrapper to stop a process after N seconds
16 binmode \*STDOUT, ":utf8";
17 binmode \*STDERR, ":utf8";
22 my $message = shift || "";
24 $time = 100 if !defined $time;
28 warn "Time out alarm $time\n";
30 # sends a hang-up signal to all processes in the current process group
31 local $SIG{HUP} = "IGNORE";
35 local $SIG{TERM} = "IGNORE";
40 warn "Send a hang-up to all childs.\n";
43 warn "set alarm time to: $time seconds $message\n" if $debug >= 1;
49 usage: $0 [ options ] command args ....
51 --debug=0..3 debug option, default: $debug
52 --timeout=1..N timeout in seconds, default: $timeout
59 "timeout=f" => \$timeout,
65 die usage if !@system;
67 set_alarm( $timeout, join( " ", @system ) );
70 or die "@system failed with exit code: $?\n";