How to find which application is using the port on AIX/Linux ?
Sometimes a process might fail to start because the port is being used by a different application with like ” error 7180 port is using by process ” . To find which application is using the port or port is being used by which process , run netstat followed by rmsock on AIX and on Linux, netstat can alone answer your question .On AIX
1. netstat -Aan | grep [Port No]- This shows if the specified is being used. The hex number in the first column is the address of protocol control block (PCB)
2. rmsock [Port No] tcpcb - This shows the process who is holding the socket means port is being used by which process.
Note: This command must be run as root.
AIX Example
$ netstat -Aan | grep 30542 f1000e000949b3b8 tcp4 0 0 *.30542 *.* LISTEN f1000e0009471808 stream 0 0 f1000a006998bc20 0 0 0 /var/ct/IW/soc/mc/clsrv f1000e0009467180The netstat command above shows that the port 30542 is being used for listening means ”port is being used” . The rmsock as below command belwo shows it’s PSRENSRV process that’s using the port and its PID is 7180
$ rmsock f1000e000949b3b8 tcpcb The socket 0xf1000e000949b008 is being held by proccess 21299652 (PSRENSRV).Now grep the process details
$ ps -ef |grep -i 21299652 root 20906300 22413462 0 03:07:14 pts/2 0:00 grep -i 21299652 psuser 21299652 1 0 Nov 30 - 12:53 PSRENSRV -C dom=HRSND91_58337 -g 92 -i 101 -u webmanual01 -U /ps/psuser/appserv/HRWEB91/LOGS/TUXLOG -m 0 -o ./LOGS/stdout -e ./LOGS/stderr -A ---D HRWEB91 -S PSRENSRV
On Linux ( port is being used )
1. netstat -anp | grep [Port No]
- This shows the PID and the program name that uses the port means port is being used by which process. The command must be run as root.
2. Alternatively, one can also run fuser -n tcp [Port No]
Linux Example
Suppose the port 12345 is being used by someone else. Find out who by running the following.
# netstat -anp | grep 12345 # netstat -anp | grep 12345 tcp 0 0 127.0.0.1:12345 0.0.0.0:* LISTEN 6629/ssh tcp 0 0 ::1:12345 :::* LISTEN 6629/sshssh with the PID 6629 is using the port. Find more info about it.
# ps -efl | grep 6629 4 S root 6629 29716 0 75 0 - 6976 - 14:05 pts/4 00:00:00 ssh testserver -D 12345 -l db2inst1 0 S root 7648 7302 0 78 0 - 742 pipe_w 14:07 pts/7 00:00:00 grep 6629
* Source Article from : Internet