Operating System - HP-UX
1835272 Members
2649 Online
110078 Solutions
New Discussion

How can I know the relation of port number and process?

 
westpanda_1
New Member

How can I know the relation of port number and process?

When I install a program of CHINA-LUCENT, I found the port number 8010 has been occupied, than I use "netstat -an | grep 8010" to confirm it.

I want to know what process occupy the port number 8010, and I want to kill the process to release the port number "8010".
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: How can I know the relation of port number and process?

You might be able to use lsof and netstat to do the job.

The best you can do is look at /etc/services

That file is like a reservation system and might get you enough information to move forward.

SEP
SIT
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Con O'Kelly
Honored Contributor

Re: How can I know the relation of port number and process?

Hi

The netstat command is not great for providing info on what processes are tied to the port.
The 'lsof' command is much better and will give you the info you need:
# lsof -i :8010

You need to download lsof from:
http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.71/

Cheers
Con
Petr Simik_1
Valued Contributor

Re: How can I know the relation of port number and process?

#lsof is the best solution
http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.71/

I use this exactly for the same purpose. Killing processes according to openned port.

than you can make script to automate this procedure.

process=`lsof -n|grep 8010|awk '{ print $2 }'`
for proc in $process
do
#echo $proc
kill $proc
done
rick jones
Honored Contributor

Re: How can I know the relation of port number and process?

/etc/services isn't _really_ a "reservation" mechanism - simply putting a port number in /etc/services will not preclude another process from using that port number. it is better to think of /etc/services as a place to store a "service name" to port number mapping.

the suggestions about lsof are the way to go.

now, if netstat shows no connection in LISTEN state on that port number and the problem to be solved is the startup of a server application, then the server application is broken because it isn't setting SO_REUSEADDR before trying to bind to its well-known port number. lsof and process killing would only be a kludge in such a case.
there is no rest for the wicked yet the virtuous have no pillows
D Block 2
Respected Contributor

Re: How can I know the relation of port number and process?

Hi WestPanda,

as a measure of testing what ports can be opened on your server, and using LSOF (great tool, BTW). you also can do the following test:

on a client system window:
telnet
on the server:
netstat -an | grep
lsof |grep

try: telnet
Golf is a Good Walk Spoiled, Mark Twain.
Saravanan_11
Occasional Advisor

Re: How can I know the relation of port number and process?

load_proce=`lsof -i :8010|awk '{print $2}'|uniq`
for proce in $load_proce
do
kill $load_proce
done

It shall kill the processes that r using the port 8010. lsof -i is the best option to list the applications.

-Saravanan
Jan Sladky
Trusted Contributor

Re: How can I know the relation of port number and process?

hi,
I have looked into /etc/servies and port 8010 is Unassigned

# 8023-8031 Unassigned

for relation between process and port use netstat or lsof as was mentioned above

br Jan
GSM, Intelligent Networks, UNIX