What are the ways to find which process is using which network port? Is there a known issue where the PID can't be found?
I have a custom written process (written in Java although shouldn't matter) which many times after exiting (but not always) its listen port is still shown as LISTEN in a netstat -an output. The process is gone though (I have exited it).
Here is a little snippet of a command-line session after the process has quit (my process listens on port 8181):
You can see that something is still listening on port 8181 because I can telnet to it.
mjparme:~:4> telnet localhost 8181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
telnet> quit
Connection closed.
However a lsof doesn't find it (a sudo lsof | grep 8181 doesn't return results either)
mjparme:~:5> sudo lsof -i TCP:8181
Nothing in ps shows that port (although the port is read from a property file rather than the command line so wouldn't really expect to see it here)
mjparme:~:6> ps auxww | grep 8181
mjparme 608 0.0 0.0 599780 392 s000 R+ 5:34PM 0:00.00 grep 8181
The netstat still shows it listening. If netstat shows it why doesn't lsof show it?
mjparme:~:7> netstat -an | grep 8181
tcp6 5 0 ::1.8181 ::1.54606 CLOSE_WAIT
tcp6 0 0 ::1.8181 ::1.54605 CLOSE_WAIT
tcp4 0 0 127.0.0.1.8181 127.0.0.1.51365 CLOSE_WAIT
tcp46 0 0 *.8181 *.* LISTEN
tcp6 0 0 ::1.54606 ::1.8181 FIN_WAIT_2
tcp6 0 0 ::1.54605 ::1.8181 FIN_WAIT_2
Some flavors of the netstat command accepts a -p option which shows the PID of the owning process, the Mac OS version doesn't appear to do that.
My main question: Is there another way to find the PID of the process that is still LISTENing on that port?
This process runs great on Windows and Linux (actually runs on Linux in production). I recently got a Mac at work so have started to do development on my Mac. (On windows on linux when the process exits that port is no longer LISTENing)
I am unsure if I am dealing with a Mac OS bug or an Apple JVM bug. Or maybe I have a coding error that is exposed in the apple JVM but not on windows or linux.
I have a custom written process (written in Java although shouldn't matter) which many times after exiting (but not always) its listen port is still shown as LISTEN in a netstat -an output. The process is gone though (I have exited it).
Here is a little snippet of a command-line session after the process has quit (my process listens on port 8181):
You can see that something is still listening on port 8181 because I can telnet to it.
mjparme:~:4> telnet localhost 8181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
telnet> quit
Connection closed.
However a lsof doesn't find it (a sudo lsof | grep 8181 doesn't return results either)
mjparme:~:5> sudo lsof -i TCP:8181
Nothing in ps shows that port (although the port is read from a property file rather than the command line so wouldn't really expect to see it here)
mjparme:~:6> ps auxww | grep 8181
mjparme 608 0.0 0.0 599780 392 s000 R+ 5:34PM 0:00.00 grep 8181
The netstat still shows it listening. If netstat shows it why doesn't lsof show it?
mjparme:~:7> netstat -an | grep 8181
tcp6 5 0 ::1.8181 ::1.54606 CLOSE_WAIT
tcp6 0 0 ::1.8181 ::1.54605 CLOSE_WAIT
tcp4 0 0 127.0.0.1.8181 127.0.0.1.51365 CLOSE_WAIT
tcp46 0 0 *.8181 *.* LISTEN
tcp6 0 0 ::1.54606 ::1.8181 FIN_WAIT_2
tcp6 0 0 ::1.54605 ::1.8181 FIN_WAIT_2
Some flavors of the netstat command accepts a -p option which shows the PID of the owning process, the Mac OS version doesn't appear to do that.
My main question: Is there another way to find the PID of the process that is still LISTENing on that port?
This process runs great on Windows and Linux (actually runs on Linux in production). I recently got a Mac at work so have started to do development on my Mac. (On windows on linux when the process exits that port is no longer LISTENing)
I am unsure if I am dealing with a Mac OS bug or an Apple JVM bug. Or maybe I have a coding error that is exposed in the apple JVM but not on windows or linux.