test/sun/jvmstat/testlibrary/utils.sh

Print this page




 172 
 173     kill -TERM ${kpid}          # hit it easy first
 174     if [ $? -eq 0 ]
 175     then
 176         sleep 2
 177         kill -0 ${kpid} 2>/dev/null
 178         # check if it's still hanging around
 179         if [ $? -eq 0 ]
 180         then
 181             # it's still lingering, now it it hard
 182             kill -KILL ${kpid} 2>/dev/null
 183             if [ $? -ne 0 ]
 184             then
 185                 echo "Could not kill ${kpid}!"
 186             fi
 187         fi
 188     else
 189         echo "Error sending term signal to ${kpid}!"
 190     fi
 191 }




































 172 
 173     kill -TERM ${kpid}          # hit it easy first
 174     if [ $? -eq 0 ]
 175     then
 176         sleep 2
 177         kill -0 ${kpid} 2>/dev/null
 178         # check if it's still hanging around
 179         if [ $? -eq 0 ]
 180         then
 181             # it's still lingering, now it it hard
 182             kill -KILL ${kpid} 2>/dev/null
 183             if [ $? -ne 0 ]
 184             then
 185                 echo "Could not kill ${kpid}!"
 186             fi
 187         fi
 188     else
 189         echo "Error sending term signal to ${kpid}!"
 190     fi
 191 }
 192 
 193 # check to see if a port is free
 194 checkPort() # port
 195 {
 196     inuse=`netstat -a | egrep "\.$1"`
 197     if [ "${inuse}" = "" ] ; then
 198       echo "free"
 199     else
 200       echo "inuse"
 201     fi
 202 }
 203 
 204 # Get a free port, where port+1 is also free, return 0 when giving up
 205 freePort()
 206 {
 207   start=3000
 208   while [ ${start} -lt 3030 ] ; do
 209     port1=`expr ${start} '+' $$ '%' 1000`
 210     port2=`expr ${port1} '+' 1`
 211     if [ "`checkPort ${port1}`" = "inuse" \
 212          -o "`checkPort ${port2}`" = "inuse" ] ; then
 213       start=`expr ${start} '+' 1`
 214     else
 215       break
 216     fi
 217   done
 218   if [ "`checkPort ${port1}`" = "inuse" \
 219        -o "`checkPort ${port2}`" = "inuse" ] ; then
 220     port1="0"
 221   fi
 222   echo "${port1}"
 223 }
 224 
 225