Operating System - HP-UX
1832367 Members
2947 Online
110041 Solutions
New Discussion

How to release a locked port

 
John M_1
Occasional Contributor

How to release a locked port

Hello all,

I executed the following command:
netstat -a |grep 1225

I got the following output:
tcp 0 0 *.1225 *.* LISTEN

I also grep'ed for the port using the following
command:
ps -ef |grep 1225

I didn't get any output. Wondering if there
is any other way of release this port.

Thanks very much in advance,
John
5 REPLIES 5
Stefan Farrelly
Honored Contributor

Re: How to release a locked port

The unorthodox method of using tcp_discon or tcp_discon_by_addr allows terminating of connections in the connections table without the need for a reboot. However, my advice is to
use it only as a last resort.

To use the ndd -set /dev/tcp tcp_discon, you need the pointer to the TCP instance data. You can retrieve this via the ndd command tcp_status.

So, the scenario to find the TCP instance data and then use tcp_discon to remove the instance is as follows:

# ndd -get /dev/tcp tcp_status
TCP dest snxt suna swnd cwnd rnxt rack rwnd rto mss [lport,fport] state

0183b8b4 015.043.233.086 533cb8ce 533cb8ce 00008000 00003000 533bc583 533bc583
00000000 02812 04096 [c00a,cea9] TCP_CLOSE_WAIT

So, if you wanted to remove this connection:
# ndd -set /dev/tcp tcp_discon 0x0183b8b4

If you want to use the tcp_discon_by_addr, you use a 24 byte string that contains the hex
representation of the quadruple.

For example, if the connection that I want to delete is:

Local IP: 192.1.2.3 (0xc0010203)
Local Port: 1024 (0x0400)
Remote IP : 192.4.5.6 (0xc0040506)
Remote Port: 2049 (0x0801)

The "hex" string you pass to tcp_discon_by_addr is:

# ndd -set /dev/tcp tcp_discon_by_addr "c00102030400c00405060801"

NOTE: the preceding 0x that typically indicates a Hex number is NOT part of the
string passed.

Im from Palmerston North, New Zealand, but somehow ended up in London...
rick jones
Honored Contributor

Re: How to release a locked port

i would like to amplify what stephan said and say that never should you need to use those ndd kludges. all it takes is one slippup in reading the tcp_status output and you toast some other, possibly quite vital connection.

to find the process or processes with references to the given port number you should download th elsof tool from the net - perhaps the hpux.connect.org.uk archive and run that. then you can terminate that process to free-up the port.
there is no rest for the wicked yet the virtuous have no pillows
Sridhar Bhaskarla
Honored Contributor

Re: How to release a locked port

Hi John,

You can use tcp_discon or tcp_discon_by_addr as suggested by Stephan but is not recommended.

Also, lsof from our hp distribution center is only for 32bit and if you have 11.0 64bit OS, it won't help you. You will need to recompile.

Best place to get lsof for 64bit is the following site

ftp://ftp.fu-berlin.de/pub/unix/tools/lsof/binaries/hpux/B.11.00/vxfs/64/9000_800/

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Anil C. Sedha
Trusted Contributor

Re: How to release a locked port

John,

If you haven't used this port in /etc/services and want to free up this port.

Do this.

lsof -i servername:portnumber

This will give you the process id's

You kill the process running on this port number.

By the way, "lsof" is available as a freeware, and you may get it on hp-ux porting website. Also, it is easy to install as it's available as a .depot file.

Regards,
Anil
If you need to learn, now is the best opportunity
MANOJ SRIVASTAVA
Honored Contributor

Re: How to release a locked port

John


You would need to download the lsof utlilty from this site :

ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/



then you can run lsof | grep 1225 this will shown as a port for a process which can be killed to realease the por t, howver the other ports wiht the process will aslo ge tkilled , also you have 32 /64 bit binaries for the bothe the flacours of HPUX so that it can be easliy configured. Incase you cannot do that please send me your email id and I will send you the comipled version of losf


Manoj Srivastava