Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have many processes on a box listening on several ports.
I am trying to map ports to pids.
The problem is that lsof is not telling me what ports belong to which process.

Given an apache listening on port 80, I can see it listening via netstat:
user@host% netstat -an|grep LISTEN|grep 80
*.80 *.* 0 0 49152 0 LISTEN

But when I try to map port 80 to a pid I get nothing:
user@host% lsof -iTCP:80 -t

When I try seeing what sockets that specific pid is using I get:
user@host% lsof -lnP -p31 -a -i
libhttpd. 31 0 15u IPv4 0x6002d970b80 0t0 TCP *:65535 (LISTEN)

Notice the *:65535 in the NAME column.

Does anyone know why lsof is not reporting the port in use?

I am running as root. I am using a mix of lsof and os versions:
lsof v4.77 on Solaris10 sparc
lsof v4.72 on Redhat4.2

I know that linux solutions can use "netstat -p",
so I guess I'm only looking for why solaris isn't working, but I find lsof is frequently silent and not showing me expected data.

share|improve this question
up vote 2 down vote accepted

You'd rather use pfiles which is part of Solaris and supported by Sun, unlike lsof.

Its usage is slightly different as it expects a pid as argument but you can achieve what you want with something like:

pfiles $(pgrep libhttpd)

or even, if you don't know the process name:

pfiles /proc/*  
share|improve this answer
pfiles 31 shows me which ip:port it is bound to... that's likely to get me where I need to go... – ericslaw Mar 18 '10 at 1:36
oh dear, this is scary: "[pfiles will] stop their target processes while inspecting them and reporting the results" that sounds very very bad – ericslaw Apr 16 '10 at 18:09
Indeed, that might be an issue for processes with an extremely large number of open files. Here is a nice alternative that doesn't stop processes: – jlliagre Apr 16 '10 at 22:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.