From d3bd46ad52c26949d7523b135c22462108c2b297 Mon Sep 17 00:00:00 2001 From: graehl Date: Mon, 28 Jun 2010 01:18:00 +0000 Subject: run netstat once only, and w/ windows compat options git-svn-id: https://ws10smt.googlecode.com/svn/trunk@34 ec762483-ff6d-05da-a07a-a48fb63a330f --- vest/parallelize.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'vest') diff --git a/vest/parallelize.pl b/vest/parallelize.pl index 7a4a2133..45152144 100755 --- a/vest/parallelize.pl +++ b/vest/parallelize.pl @@ -29,6 +29,9 @@ my $verbose = 1; my $numnodes; my $user = $ENV{"USER"}; my $pmem = "2g"; +my $basep=50300; +my $randp=300; +my $tryp=50; sub print_help; @@ -41,7 +44,9 @@ if (GetOptions( "file=s" => \@files_to_stage, "verbose" => \$verbose, "jobs=i" => \$numnodes, - "pmem=s" => \$pmem + "pmem=s" => \$pmem, + "baseport=i" => \$basep, + "iport=i" => \$randp, #ugly option name so first letter doesn't conflict ) == 0 || @ARGV == 0){ print_help(); } @@ -89,13 +94,14 @@ $executable=`basename $executable`; chomp $executable; # find open port -my $basep=50300; -my $randp=300; -my $tryp=50; +srand; my $port = 50300+int(rand($randp)); my $endp=$port+$tryp; +my $netstat=`netstat -a -n 2>/dev/null | grep LISTENING | grep -i tcp`; + if ($verbose){ print STDERR "Testing port $port...";} -while (`netstat -ln 2>/dev/null | grep $port`){ + +while ($netstat=~/$port/s){ if ($verbose){ print STDERR "port is busy\n";} $port++; if ($port > $endp){ @@ -107,7 +113,6 @@ if ($verbose){ print STDERR "port $port is available\n"; } -srand; my $key = int(rand()*1000000); my $multiflag = ""; -- cgit v1.2.3