From: Wolfram Schneider Date: Thu, 6 Feb 2014 15:45:50 +0000 (+0100) Subject: documentation X-Git-Tag: 1.0.0~1517 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=a7792332dcc085339310bc98575b6f5f86302a83;p=mkws-moved-to-github.git documentation argument checking --- diff --git a/test/bomp.pl b/test/bomp.pl new file mode 100755 index 0000000..a84f40b --- /dev/null +++ b/test/bomp.pl @@ -0,0 +1,73 @@ +#!/usr/local/bin/perl +# Copyright (c) 2014 IndexData ApS. http://indexdata.com +# +# bomb.pl - wrapper to stop a process after N seconds +# + +use Getopt::Long; + +use strict; +use warnings; + +my $debug = 0; +my $help; +my $timeout = 100; + +binmode \*STDOUT, ":utf8"; +binmode \*STDERR, ":utf8"; + +# timeout handler +sub set_alarm { + my $time = shift; + my $message = shift || ""; + + $time = 100 if !defined $time; + + $SIG{ALRM} = sub { + + warn "Time out alarm $time\n"; + + # sends a hang-up signal to all processes in the current process group + # and kill running java processes + local $SIG{HUP} = "IGNORE"; + kill 1, -$$; + + local $SIG{TERM} = "IGNORE"; + kill 15, -$$; + kill 15, -$$; + + warn "Send a hang-up to all childs.\n"; + + #exit 1; + }; + + warn "set alarm time to: $time seconds $message\n" if $debug >= 1; + alarm($time); +} + +sub usage () { + < \$help, + "debug=i" => \$debug, + "timeout=i" => \$timeout, +) or die usage; + +my @system = @ARGV; + +die usage if $help; +die usage if !@system; + +set_alarm( $timeout, join( " ", @system ) ); + +system(@system) == 0 + or die "system @system failed: $?"; + +exit(0);