Lookup PID from Port.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason8

    Lookup PID from Port.

    Does anyone know if you can lookup the PID that owns a socket (based
    on port number) programmaticall y? I know most systems have LSOF for
    this but I'd like it to be more portable and not call an external
    program.
  • Antoninus Twink

    #2
    Re: Lookup PID from Port.

    On 6 Jun 2008 at 22:49, Jason8 wrote:
    Does anyone know if you can lookup the PID that owns a socket (based
    on port number) programmaticall y? I know most systems have LSOF for
    this but I'd like it to be more portable and not call an external
    program.
    I can't think off-hand of a library that does this, strange to say. I'd
    advise you to have a look at the source code to netstat on your platform
    (e.g. on Debian it's in the net-tools package) and pick out the bits
    where it does the relevant magic.

    Comment

    • Keith Thompson

      #3
      Re: Lookup PID from Port.

      Jason8 <jason.leach@gm ail.comwrites:
      Does anyone know if you can lookup the PID that owns a socket (based
      on port number) programmaticall y? I know most systems have LSOF for
      this but I'd like it to be more portable and not call an external
      program.
      The C language itself doesn't define PIDs, sockets, or port numbers.

      Try comp.unix.progr ammer.

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      Nokia
      "We must do something. This is something. Therefore, we must do this."
      -- Antony Jay and Jonathan Lynn, "Yes Minister"

      Comment

      • Kenny McCormack

        #4
        Re: Lookup PID from Port.

        In article <lnmylyb101.fsf @nuthaus.mib.or g>,
        Keith Thompson <kst-u@mib.orgwrote:
        >Jason8 <jason.leach@gm ail.comwrites:
        >Does anyone know if you can lookup the PID that owns a socket (based
        >on port number) programmaticall y? I know most systems have LSOF for
        >this but I'd like it to be more portable and not call an external
        >program.
        >
        >The C language itself doesn't define PIDs, sockets, or port numbers.
        >
        >Try comp.unix.progr ammer.
        Thank you for your helpful contribution.

        Comment

        Working...