Operating System - HP-UX
1824994 Members
2247 Online
109678 Solutions
New Discussion юеВ

Re: How to kill an open port after the prog. which start it already ended?

 
YLTan
Frequent Advisor

How to kill an open port after the prog. which start it already ended?

i have a program that uses a port 1978 when it started. When the program shuts down, the port still alive and listening. I can see it by netstat -an |grep 1978. Now I can't start the program because it says the port is already being use.

How to shutdown the port?
tyl
3 REPLIES 3
Steven Sim Kok Leong
Honored Contributor

Re: How to kill an open port after the prog. which start it already ended?

Hi,

First, use lsof to check for any processes still binding to the port.

If that does not work, then use ndd to force close the connection (though not recommended) via tcp_discon and/or tcp_discon_by_addr. Details at:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xbe06a22d6d27d5118fef0090279cd0f9,00.html

Hope this helps. Regards.

Steven Sim Kok Leong
Bill McNAMARA_1
Honored Contributor

Re: How to kill an open port after the prog. which start it already ended?

What state does netstat say it's in?

You might want to ensure you have no FIN_WAIT states.

Check for ARPA patches if there are.

(search for FIN_WAIT2 in the patch Database)

Later,
Bill
It works for me (tm)
Steven Gillard_2
Honored Contributor

Re: How to kill an open port after the prog. which start it already ended?

It depends what state the port is in. If its still in listen state then you'll have to use lsof as Steven suggests to track down the process that has bound to the port.

A lot of the time you'll find that there are TIME_WAIT sockets which are held open for another 4 minutes (by default) after the socket is closed. While these sockets are present another process cannot bind() to the port. There are two ways around this:

1. Wait until the time_wait sockets have disappeared before starting the application.

2. Have the application set the SO_REUSEADDR flag on the socket before calling bind(). The bind() call will now succeed even if there are sockets in the time_wait state still present. Obviously this requires a change to the code so you'll need to go back to the developers or your application vendor.

Regards,
Steve