Home / Solaris 10 / Solaris Local Zone’s lsof

Solaris Local Zone’s lsof

In Solaris local zone lsof will not work.By default all the application should have configured with specific port number.But sometimes your application will not start if that port has been already occupied by another application process.In this situation, you will get error like “unable to bind port <port-number>”if you try to start the application. Traditionally we will use lsof command to determine what process is using the particular port.But in Solaris 10 local zones , you can’t use lsof. The below script will help you to find what process is occupying the specific port on Solaris servers and this script will be very useful on Solaris zones.
 
Script :
#!/bin/ksh
# Website-www.UnixArena.com
line='---------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')

if [ $# -eq 0 ]; then
   read ans?"Enter port you would like to know pid for: "
else
   ans=$1
fi

for f in $pids
do
   /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
   if [ $? -eq 0 ]; then
      echo $line
      echo "Port: $ans is being used by PID:\c"
      /usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
   fi
done
exit 0

How to use the script ?
1.Copy the script to Solaris local zones and make the script as executable.

# chmod 555 check_port.sh
# ls -lrt check_port.sh
-r-xr-xr-x   1 root     root         517 Jan 29 10:11 check_port.sh
#


2.Execute the script  and enter the port number.

# ./check_port.sh
Enter port you would like to know pid for: 8232
---------------------------------------------
Port: 8232 is being used by PID:12864 /usrweb/exe/jlaunch pf=/usr/web/SYS/profile/mydb -SD
---------------------------------------------
#
#


3.Once you got the process ID ,then its easy to trace it about that process.

# ps -ef |grep 12864
  ora1adm 12864  327   0   Jan 19 ?          25:51 /usrweb/exe/jlaunch pf=/usr/web/SYS/profile/mydb -SD
    root 29676 17719   0 10:13:34 pts/49      0:00 grep 12864
#


You can check with the ora1adm user and ask him to stop the process if you want to use the port 8232 for other applications.If the user is not able to stop this process,you can kill the process using pkill pid or kill -9 pid commands with proper approvals. 

Thank you for visiting UnixArena.

VMTURBO-CLOUD-CAPACITY

One comment

  1. It’s possible on Solaris to be more efficient (less created processes, fewer resources consumed).

    Replace “pids=$(/usr/bin/ps -ef | sed 1d | awk ‘{print $2}’)” by “pids=$(ps -e -o pid=)”.

Leave a Reply

Your email address will not be published. Required fields are marked *