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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
prtdiag report hdd failure 10 120
Help stop mail server from sending spam. 27 117
aix tls version 6 154
unix example issues 18 47
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now