Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to force a port to close ??

Status
Not open for further replies.

qt11

IS-IT--Management
Sep 27, 2005
2
GB
Hey guys

we have a java based server side web application that runs over a specific port on Solaris 8.

Unfortunately, sometimes this app crashes or hangs and requires a restart.

We have a problem that the port the application uses is not released upon a crash and therefore the only way to really clear the problem and restart the service is to restart the server... not a good solution...

I thought that ports should auto close if they are not used for a period of time, however this does not seem to be the case here. The port stays open indefinitely...

Is there a way of forcing a port to close from the command line ??

Please help

Cheers
A
 
There is probably a process not being fully killed. I would look into lsof or if you know the port number try a netstat -na and grep for the port number.
 
coffeysm, thanks for the reply...

yes, this is pretty much what we though too, however I believe that i've killed all the processes relating to the app, however the port remains open.

netstat -na shows the port is open on TIME_WAIT.

i found this script here on the boards, I don't recall who wrote it, however thankyou to them...

Code:
#!/bin/ksh

line='-------------------------------------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')


# Prompt users or use 1st cmdline argument
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"
        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

we do know the ports and this helps to see the processes involved..

However am still searching for a quick and easy way of forcing a port to close

Cheers
qt11
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top