Two ways to get which process is Listen on the specific port on Solaris
1. lsof -i:port_number
e.g. lsof -i:22
2. Use scripts that combined with pfiles
e.g. get_port.sh 22
#!/bin/bash
# Get the process which listens on port
# $1 is the port we are looking for
if [ $# -lt 1 ]
then
echo “Please provide a port number parameter for this script”
echo “e.g. $0 22″
exit
fi
echo “Greping for your port, please be patient (CTRL+C breaks) … ”
for i in `ls /proc`
do
pfiles $i | grep AF_INET | grep $1 |grep -v pfiles
if [ $? -eq 0 ]
then
echo;echo “PID is $i and Process details run on port:$1″;echo
ps -cafe|grep $i|grep -v grep
fi
done
#1 by jurgyman on 2010-06-16 - 12:59
WARNING:
use of pfiles on a process PAUSES the process.
this burned me on a real-time critical app server where I was using pfiles to count in and outbound connections.
it sux there is no native solaris support for: netstat -p or lsof -i like functionality.
#2 by edyliu on 2010-06-16 - 18:38
cool, tks for ur share.
it indeed make guys from linux headache.