Additional menu

Check PID using Port Number in Solaris

Check PID using Port Number in Solaris

Geek Flare Blog post is sponsored by Netsparker Web Application Security Scanner.

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

If you are working on new services setup 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 file to be executable
chmod 754 $filename
  • Execute the file

Easy. Were you able to find the PID now?

If you are interested in learning, then check out this essential Linux administration course.

Reader Interactions

Chandan Kumar
About Chandan
Chandan Kumar is the founder of Geek Flare. Learn more here and connect with him on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share
Tweet
Stumble
Share