From 9b0c3f100ffa7edd1e030a149431a2e6cc9a4def Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Mon, 17 Jun 2013 17:50:35 +0000 Subject: [PATCH] Add timeout to psh git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@16647 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/bin/psh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/xCAT-client/bin/psh b/xCAT-client/bin/psh index 23ed4a08f..bdb1db4e1 100755 --- a/xCAT-client/bin/psh +++ b/xCAT-client/bin/psh @@ -21,11 +21,13 @@ use Thread qw(yield); my $interface; my $username; my $help; +my $timeout=0; Getopt::Long::Configure("require_order"); Getopt::Long::Configure("no_pass_through"); if (!GetOptions( "i|interface=s" => \$interface, 'l|loginname=s' => \$username, + 't|timeout=s' => \$timeout, 'f|fanout=s' => \$fanout, "nonodecheck" => \$::NONODECHECK, #does not check the noderange, in this case, noderange need to be a list of nodes. 'h|help' => \$help, @@ -102,6 +104,26 @@ if ($interface) { s/$/-$interface/; } } +local $SIG{ALRM}= sub { + my @proclist = `ps -ef`; + my %ownedpids; + foreach (@proclist) { + m/\S+\s+(\S+)\s+(\S+)/; + $ownedpids{$2}=$1; #only recall one child per parent + } + foreach my $pid (keys %pids) { + my $node = $pids{$pid}; + unless (defined $exitcodes{$node}) { + print stderr "$node: timeout exceeded\n"; + if ($ownedpids{$pid}) { + kill 15,$ownedpids{$pid}; + } else { + kill 15,$pid; + } + } + } +}; +if ($timeout) { alarm($timeout); } foreach (@nodes) { my $node=$_; while ($children >= $pshmaxp) { processoutput($inputs); }