Getting which pid uses a specific port on SunOS 5.8

Posted on 2004-09-30
Last Modified: 2012-05-05
How would I be able to get pid that uses a specific port on SunOS 5.8?

More important is if you could tell me what did you/should I reference to answer this next time.

Thank you.
Question by:InGearX
LVL 38

Accepted Solution

yuzh earned 38 total points
ID: 12196145
Here's a script for you to do the job:

echo -n "which port?> "
read port

for pid in `ps -ef -o pid | tail +2`
  foundport=`pfiles $pid 2>&1 | grep "sockname:" | grep "port: $port$" |
'{print $NF}'`
  if [ "$foundport" != "" ]; then
    foundproc=`pfiles $pid 2>&1 | grep "^$pid:"`
    echo "$foundproc, $foundport"



Assisted Solution

mdhmi earned 37 total points
ID: 12388924

Use lsof.  If you don't already have lsof you can download it from



Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vmware Vswitch  VS  Redhat  Bridge 1 120
FTP on FreeBSD server 2 152
Write an app 10 73
How to clone solaris 10 machine 33 167
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question