Operating System - HP-UX
1748180 Members
4216 Online
108759 Solutions
New Discussion

process Or IP connected to specific port on Hp-ux Server

 
RaviAR
Occasional Visitor

process Or IP connected to specific port on Hp-ux Server

We are running a java socket Server program in our hp-ux server.

Some issue occured and java programe went hung status.After restaring the java program thing are started woking.

Now i want know what are the ip and process connected to that Java program.

 

 

 

 

6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: process or IP connected to specific port on HP-UX

You'll need to use netstat and lsof(1m) to get this info.

Bill Hassell
Honored Contributor

Re: process Or IP connected to specific port on Hp-ux Server

netstat comes with standard HP-UX.
You'll need to download lsof from http://software.hp.com

 



Bill Hassell, sysadmin
RaviAR
Occasional Visitor

Re: process or IP connected to specific port on HP-UX

Thanks for your post.

We have netstate and lsof commands in over server.

but netstat will give you the current connection details only right.?correct me if am wrong..

How shall i get IP connected to specific port details in netstat and lsof?

Can you plese share some sample commads.

Bill Hassell
Honored Contributor

Re: process or IP connected to specific port on HP-UX

netstat and lsof will give you details about the currentlty running system. They cannot report what happened in the past. You'll need to add some logging to your application and when the hang occurs, run netstat and lso at that time. You'll need to read the man pages for the appropriate options.



Bill Hassell, sysadmin
RaviAR
Occasional Visitor

Re: process or IP connected to specific port on HP-UX

Thanks for your info.

Matti_Kurkela
Honored Contributor

Re: process Or IP connected to specific port on Hp-ux Server

The other answers already covered how to get information about current connections.

The original question seems a bit of vague: is the connection you wish to know about local to this single host (i.e. two processes talking to each other using a network socket) or is it a remote connection from some other host? Or maybe you don't know that?

In general, the IP addresses are managed by the host OS (or clustering software). When an application (whether Java or any other) prepares a network socket for receiving incoming connections, it will execute a bind() system call. Usually this system call is executed with parameters that specify only the port number: in this case, the application's socket will listen for incoming connections to the specified destination port on all IP addresses the system has.

However, it is possible to also specify the IP address when executing the bind() system call. In that case, the application's socket will listen for incoming connections on that specific destination IP address + destination port combination only. That IP address must be configured on the system the application is running on, or else the system call may fail.

Note that this bind() system call is something the application must do: the operating system cannot supply this information. If your application does not include a configuration option to bind the application's listening socket(s) to a particular IP address, then the application will probably always listen on all IP addresses the system has. If you want to change this, you must make changes to the application.

Java has various simplified ways for making a TCP (or HTTP) connection without explicitly doing a bind() system call.  Unfortunately, the simplicity may come with the price of reduced functionality: to access some useful TCP features you may have to use the full-featured socket interface in the application code instead of e.g. the simplified java.net.HTTPUrlConnection class.

While the netstat and lsof commands can be used to query the system for current connections, it is generally the application's responsibility to log the source IP address of any incoming connection if a record of past connections might be needed. If the application does not have such a logging feature, it might be possible to install the optional IPFilter package and use its IPFILTER_LOG option to configure the OS to log the relevant details of any incoming connections on behalf of the application with insufficient logging capabilities. But this is just a workaround, not a real solution.

In general, an application that is receiving an incoming network connection through a TCP socket will fundamentally know only four things about that connection. These are also the things that separate that TCP connection from any others. In regular old TCP/IP with IPv4, these things cannot be changed once the connection is established without tearing down the connection and establishing a new one:

  • the source IP address of the connection
  • the source port number of the connection (which is usually dynamically allocated and not very useful, except for telling apart multiple simultaneous connections from the same source host to the same destination host & port)
  • the destination IP address of the connection (which must be one of the IP addresses configured to the destination host OS)
  • the destination port number (which was chosen by the application when setting up the socket for incoming connections)

There is no information available to the destination about the process initiating the connection at the source host: the network protocols do not care about the processes, in order to allow different operating systems (with possibly very different concepts of processes) to communicate with each other. In order to identify the source process, you must use tools like lsof and/or netstat at the source host, while the connection you wish to trace is active, unless the source host can be configured to log all outgoing connections.

MK