Wednesday, April 6, 2011

Mapping a Weblogic Port to a PID.

There are multiple ways to map the PID for a running Weblogic Instance when you are running more than one Weblogic instance on a single server/zone. This post explains one of the way to map the Weblogic Port to a PID.
Save the below script as getJavaPort.ksh on a server where you run the Weblogic instance. It will be a very handy script later. You must input the Weblogic Port for which you need the PID.

getJavaPort.ksh

#!/bin/ksh
#set -x
#  getJavaPort.ksh
#  Usage:  getJavaPort.ksh <PORTNUMBER>

if [[ $# -ne 1 ]];
then
  print "USAGE:  getjavaport.ksh <PORTNUMBER>\n"
  exit 0
fi

for i in `ps -e|grep java|awk '{print $1}'`
do
   REZ=`/bin/pfiles $i|grep "port: $1"`
   if [[ $REZ != "" ]] ;
     then print "Port $1 is opened by PID $i"
   fi
done

Syntax:
/app/bea9/scripts$ ./getJavaPort.ksh <PORTNUMBER> 
  
Example:
/app/bea9/scripts$ ./getJavaPort.ksh 7001
Port 7001 is opened by PID 24046

2 comments:

Vijay Naik said...

Hi Sunil,

Can we please have more therocital explaination for this? what is this for and how will this be helpful from Admin point of view.

Sunil Nandargi said...

Technically speaking, if there are multiple java processes for multiple application instance running on a single server it would be very hard to map the Java processes with each instance.

For example: If you need a restart of a Java Application instance with port 8001 and the easiest way to stop the instance is to kill its respective PID. Now you grep for Java processes, but you end up with list of PID's. Not sure which PID to kill related to port 8001. In such case each and everyone would think if he/she had handy script by just providing the port on which application instance runs as input and get the respective PID.