Skip to main content

Posts

Showing posts from April, 2012

Finding PID of process in Solaris by port uses

There is two ways to find PID by knowing which port is used: Lsof ( L i S t O pen F iles) lsof | grep <port_number>   1. lsof doesn’t work from non-global zone. 2. Use -z option with lsof to list open files & processes with in non-global zone like “ lsof -z ” Script for know the process for port using #!/usr/bin/ksh # #grep -v "^#" /etc/services | awk '{print $2}' | cut -d"/" -f1 | sort -n | uniq >sorted-services line='-------------------------------------------------------------------------' pids=`/usr/bin/ps -ef | sed 1d | awk '{print $2}'` # Prompt users or use 1st cmdline argument while [ $# -eq 0 ]; do if [ $# -eq 0 ]; then          read ans?"Enter port you like to know pid for:  " else          ans=$1 fi # Check all pids for this port, then list that process for f in $pids do          /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans" #/export/baha/s