test/sun/jvmstat/testlibrary/utils.sh
Print this page
*** 187,191 ****
--- 187,225 ----
fi
else
echo "Error sending term signal to ${kpid}!"
fi
}
+
+ # check to see if a port is free
+ checkPort() # port
+ {
+ inuse=`netstat -a | egrep "\.$1"`
+ if [ "${inuse}" = "" ] ; then
+ echo "free"
+ else
+ echo "inuse"
+ fi
+ }
+
+ # Get a free port, where port+1 is also free, return 0 when giving up
+ freePort()
+ {
+ start=3000
+ while [ ${start} -lt 3030 ] ; do
+ port1=`expr ${start} '+' $$ '%' 1000`
+ port2=`expr ${port1} '+' 1`
+ if [ "`checkPort ${port1}`" = "inuse" \
+ -o "`checkPort ${port2}`" = "inuse" ] ; then
+ start=`expr ${start} '+' 1`
+ else
+ break
+ fi
+ done
+ if [ "`checkPort ${port1}`" = "inuse" \
+ -o "`checkPort ${port2}`" = "inuse" ] ; then
+ port1="0"
+ fi
+ echo "${port1}"
+ }
+
+