Originally posted by: Jaikishan
This abstract illustrates the steps to find out the process id by using the port number that may help the AIX System Administrators without having to install lsof.
The past experiences have shown troubles to compile the source in certain versions of AIX(v5.3) and otherwise. Therefore the attached script will help achieve the same as lsof utility does.
Some times we know the port number and may want to kill the process manually. This can be achieved using lsof command. However, past experiences show that lsof command has troubles installing/compiling particularly with certain versions of AIX. Sometimes the source of lsof compiles properly and most of the times it does not.
Therefore, to get away the use of lsof command the steps mentioned in the solution description will help find out the process id without hassles.
Before you begin to execute this script you should know the port number and check if the port number is being listened. Use the command :
netstat -an | grep "<port_number>"
The attached script "processid_from_portno.sh" which accepts port number as input and gives process id as output.
Also attached is the sample screenshot for executing the above script
Step 1. Find out the address of the port number
-
netstat -Aa | pg
output will be something like :
f100060003606b98 tcp4 0 0 *.51063
. LISTEN
f100060003489398 tcp4 0 0 *.51100
. LISTEN
f1000600035ed398 tcp4 0 0 *.51101
. LISTEN
Step 2. Take the hex address for the port number e.g. 51063
Step 3. Use sockinfo command
-
echo "sockinfo f100060003606b98 tcpcb" | kdb |grep proc
the output will be something like this :
F100070F00000000 F100070F10000000 pvproc+000000
proc/fd: 16463/562
proc/fd: fd: 562
pvproc+1013C00 16463*java ACTIVE 004F1E4 0000001 0000000147AF6400 0 0037
Step 4. Convert the hex value to decimal
-
echo "hcal 004F1E4"|kdb|grep Value
output will be:
Value hexa: 0004F1E4 Value decimal: 324068
Step 5. Find out the process id now
-
ps -fp 324068
output will be:
UID PID PPID C STIME TTY TIME CMD
root 324068 1 0 Jan 17 - 8:06 /usr/WebSphere/p11/AppServer//java/bin/java -Djava.net.preferIPv4Stack=t
#AIX-Forum