Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On a Solaris 8 server, how do I find out what process is listening on a given port? The Windows implementation of 'netstat' offers the -o and -b switches, which show the owning process ID and name respectively. Is there an equivalent under Solaris?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

lsof -i

Doesn't come installed by default, but you can get Solaris version from http://www.sunfreeware.com/

share|improve this answer
    
Which netstat option provides the owning process under Solaris? I can't seem to find one in the man page? docs.sun.com/app/docs/doc/816-1055/6m7gh31ha?a=view –  Murali Suriar May 8 '09 at 9:30
    
You're right, thought it's like Linux netstat. But in Solaris -p has different meaning. –  vartec May 8 '09 at 9:43
    
+1 for lsof, definitely worth the trouble of installing. -i takes arguments of protocol and protocol:port, so you can do something like lsof -i TCP:25 to find out who's listening to 25/tcp (hopefully your mail server!) –  jj33 May 8 '09 at 12:18
    
Great answer, i'm never going to struggle with netstat -anp | grep again –  Dave Cheney May 9 '09 at 14:56

If you don't want to or can't install lsof, you can also try the command pfiles. It prints out all the sockets open by a given process. If you had no other choice, you could iterate over all the PIDs and find the one listening to, say, port 25:

PORT=25
for p in $(ps -eo pid)
do
  OUT=$(pfiles $p)
  if [[ "$OUT" =~ port:\ ${PORT} ]]
  then
    echo $p
  fi
done
share|improve this answer

Your Answer

 
discard

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.