Operating System - HP-UX
1836459 Members
2568 Online
110101 Solutions
New Discussion

Which process is using which port

 
Adwait
Occasional Advisor

Which process is using which port

In HPUX, if I want to know which process is using port=4000, then how do I get this information.
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: Which process is using which port

Shalom,

Best bet is to install lsof.

losf is found.

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.78/

SEP
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
Robert-Jan Goossens
Honored Contributor

Re: Which process is using which port

Hi,

Lsof is usefull tool.

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.78/

# lsof -i tcp:4000

Regards,
Robvert-Jan
Adwait
Occasional Advisor

Re: Which process is using which port

Thanks guys, but is there any other way, since I do not have lsof tool installed on the servers.
A. Clay Stephenson
Acclaimed Contributor

Re: Which process is using which port

You can use netstat to determine that a given port is in use on a box but that doesn't tell you anything about which process is using the port. Lsof is the tool for this and it's one of those tools that should be installed on every UNIX box. The installation is very easy.
If it ain't broke, I can fix that.
Robert-Jan Goossens
Honored Contributor

Re: Which process is using which port

It is one of those basic tools you should install on all your servers.

You can try netstat, but there is a change netstat will only report that the port is in use.

# netstat -an | grep 4000

example below.

# netstat -an | grep 65154
tcp4 0 0 *.65154 *.* LISTEN
# lsof -i tcp:65154
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 430100 was 255u IPv4 0xf100020003cc3390 0t0 TCP *:65154 (LISTEN)

Regards,
Robert-Jan
Torsten.
Acclaimed Contributor

Re: Which process is using which port

There is nothing better than lsof!

Example for port 2301:

# lsof -i :2301
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
smhstartd 2270 root 3u IPv4 0x2970880 0t0 TCP *:2301 (LISTEN)


Download and install this tool.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Jeeshan
Honored Contributor

Re: Which process is using which port

You can do the followings

1. Check the /etc/services file to see which for which service which port are used.
2. netstat -an|grep 4000
3. or you can do lsof.

a warrior never quits