Results 1 to 2 of 2
  1. #1

    Member Since
    Dec 31, 2008
    Find process using port
    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 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.

  2. #2

    Member Since
    Oct 15, 2009
    Try lsof ....
    I just had exactly the same problem as you and found a solution (at Linux / UNIX Find Out What Program / Service is Listening on a Specific TCP Port)

    You can short network connections with lsof on OS X as well:

    lsof -Pnl +M -i4

    Grep for your port of interest and you are done.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to find the COM port number on macbook
    By Mac9346 in forum OS X - Operating System
    Replies: 10
    Last Post: 08-14-2013, 12:35 PM
  2. What is this process?
    By CatalinaAlonso in forum OS X - Operating System
    Replies: 3
    Last Post: 04-19-2009, 03:35 PM
  3. Process name: Find
    By joe.morgan in forum OS X - Operating System
    Replies: 3
    Last Post: 01-30-2007, 08:25 PM
  4. Replies: 0
    Last Post: 09-19-2006, 05:00 PM
  5. UNIX command to find out process hook
    By walkerj in forum Switcher Hangout
    Replies: 0
    Last Post: 04-23-2005, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts