Processes using the port ..



        It is always a requirement for administrators or troubleshooters to find out which process is holding the port. I have listed out few commands below to find out the same. commands differ for different Operating Systems.

SOLARIS

Note:- Execute below command in single line. Otherwise use it as a script. Replace the red marked port# with your port#.

# for i in `ls /proc`;do pfiles $i | grep AF_INET | grep 9262;if [ $? -eq 0 ];then echo "=> PORT IS OWNED BY PID $i ";fi;done 2>/dev/null

        sockname: AF_INET 0.0.0.0  port: 9262
=> PORT IS OWNED BY PID 21326
#

AIX

Here the input to rmsock command should be the output of (Orange text) netstat command.

# netstat -Aan |grep 9144
f1000e0006452bb8 tcp        0      0  *.9144                *.*                   LISTEN

# rmsock f1000e0006452bb8 tcpcb
The socket 0xf1000e0006452808 is being held by proccess 13107448 (java).
#

Linux.

Linux has many options, you can use it based on your convenience.
 
Option-1
  
# lsof -n -i :8443
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   2826 sysweb    3u  IPv4  22229      0t0  TCP        10.144.10.138:pcsync-https (LISTEN)
httpd   2855 sysweb    3u  IPv4  22229      0t0  TCP 10.144.10.138:pcsync-https (LISTEN)
#

Option-2
# ss -tanp | grep 8443
LISTEN     0      128    10.144.10.138:8443                     *:*                   users:(("httpd",pid=2855,fd=3),("httpd",pid=2826,fd=3))
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.247:24523
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.247:27071
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.248:58763
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.248:43719
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.248:9287
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.248:58095
TIME-WAIT  0      0      10.144.10.138:8443               151.171.71.247:2359
#

Option-3
# fuser -v -n tcp 8443

                     USER        PID ACCESS COMMAND
8443/tcp:        sysweb     2826 F.... httpd
                     sysweb     2855 F.... httpd
#

Option-4
# netstat -nlp | grep :8444
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 10.144.10.138:8444      0.0.0.0:*               LISTEN      2029/httpd