Tuesday, January 21, 2014

Solaris Find out the PID which using specified port number


#!/bin/bash

if [ $# -ne 1 ]; then
  echo "Usage:"
  echo "        $0 <port number?"
  exit $LINENO
fi

portNumber=$1
for i in `ls /proc`
do
  pfiles $i | grep AF_INET | grep "port: ${portNumber}$"
  if [ $? -eq 0 ]
  then
    echo Is owned by pid $i
    pargs $i
  fi
done

No comments:

Post a Comment