Home > Solaris Admin > Get processes by listening port

Get processes by listening port

#! /bin/sh

if [ $# -ne 1 ]; then
  echo "Usage: $0 "
  exit 1
fi
listen=$1


PATH=/usr/bin:/bin
export PATH


#
# skip process 0
#
cd /proc
for i in [1-9][0-9]*
do
  pfiles $i | nawk -v listen=$listen '
    BEGIN {
      found=0
    }
    NR==1 {
      process=$0
    }
    /sockname/ && $NF == listen {
      getline
      if ( ! /peername/ ) {
        found=1
        exit
      }
    }
    END {
      if ( found == 1 ) {
        printf("%s\n",process)
      }
    }'
done
Advertisements
Categories: Solaris Admin
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: