An Oracle blog about The Oracle OpenGrok

  • Tips
    July 24, 2006

Get application pid listening on a network port in Solaris (aka netstat -npl in Solaris?)

Some time ago, I was in need of this functionality.
This little silly script, however very uneffective will check which apps listents on the given port number.
Maybe I should think about writing something more effective ... or just file a Request For Enhancement against netstat on Solaris?
Script get_port_pid.sh:

# Get the process which listens on port
# $1 is the port we are looking for
if [ $# -lt 1 ]
echo "Please provide a port number parameter for this script"
echo "e.g. $0 22"
echo "Greping for your port, please be patient (CTRL+C breaks) ... "
for i in `ls /proc`
pfiles $i | grep AF_INET | grep $1
if [ $? -eq 0 ]
echo Is owned by pid $i

Join the discussion

Comments ( 2 )
  • Mads Toftum Monday, July 24, 2006
    Why not just use lsof?
    On linux you can also use fuser for it like: fuser ssh/tcp
    It might be just as good to file an RFE to extend fuser.
  • Lubos Tuesday, July 25, 2006
    Thanks for hint Mads.
    I wasn't aware that there are packages for lsof on SFW.
    It's a pity, that some stuff isn't in Solaris by default (e.g. vim :-D )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha