Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Linux Last updated: November 30, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

Finding Process ID (PID) using a port number in Solaris is not as easy as Linux.

If you are working on the setup of a new service and would like to allocate some port, you got to check if some other service uses that port.

You can find out which process is using the particular port in Solaris by below tiny shell scripts.

Following scripts will prompt you to enter the port number, and it will use pfiles command internally to give you the pid.

  • Create a file with the following
#!/bin/ksh
line='---------------------------------------------'
pids=$(/usr/bin/ps -ef -o pid=)
if [ $# -eq 0 ];
then
read ans?"Enter Port Number To Know The pid: "
else ans=$1
fi
for f in $pids do /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans" if [ $? -eq 0 ]; then echo $line echo "Port: $ans is used by PID:c" pargs -l $f
fi
done
  • Save and change the permission of the file to be executable
chmod 754 $filename
  • Execute the file

Easy. Isn’t it?

Interested in learning Linux administration? Check out these resources.

  • Chandan Kumar
    Author
    Chandan Kumar is the founder of Geekflare. He’s helped millions to excel in the digital realm. Passionate about technology, He’s on a mission to explore the world and amplify growth for professionals and businesses.
Thanks to our Sponsors
More great readings on Linux
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Monday.com is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder