Skip to content

Instantly share code, notes, and snippets.

@pung96
Created February 14, 2012 10:10
Show Gist options
  • Save pung96/1825487 to your computer and use it in GitHub Desktop.
Save pung96/1825487 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 $command = join ' ',@command;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm $timelimit;
print $command;
open my $com,'-|',$command;
while(<$com>){ print };
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