Skip to content

Instantly share code, notes, and snippets.

@pung96
Created February 14, 2012 10:15
Show Gist options
  • Save pung96/1825511 to your computer and use it in GitHub Desktop.
Save pung96/1825511 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#===============================================================================
#
# FILE: intime.pl
#
# USAGE: ./intime.pl
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Beomsu Chang (bschang), bschang@cern.ch
# COMPANY:
# VERSION: 1.0
# CREATED: 02/14/2012 11:46:48
# REVISION: ---
#===============================================================================
use strict;
use warnings;
my $timelimit = shift @ARGV;
my ( @command ) = @ARGV;
my @com = split ' ',join ' ',@command;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm $timelimit;
print join ' ',@com;
system @com;
alarm 0;
};
if ($@) {
# timed out
print "\n\n##########################################################\n";
print STDERR "error: Timeout after $timelimit seconds requesting \n";
print "##########################################################\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment