Search code examples
hp-ux

What processes are using which ports on unix?


I need to find out what ports are attached to which processes on a Unix machine (HP Itanium). Unfortunately, lsof is not installed and I have no way of installing it.

Does anyone know an alternative method? A fairly lengthy Googling session hasn't turned up anything.


Solution

  • Assuming this is HP-UX? What about the Ptools - do you have those installed? If so you can use "pfiles" to find the ports in use by the application:

    pfiles prints information about all open file descriptors of a process. If file descriptor corresponds to a file, then pfiles prints the fstat(2) and fcntl(2) information.

    If the file descriptor corresponds to a socket, then pfiles prints socket related info, such as the socket type, socket family, and protocol family.

    In the case of AF_INET and AF_INET6 family of sockets, information about the peer host is also printed.

    for f in $(ps -ex | awk '{print $1}'); do echo $f; pfiles $f | grep PORTNUM; done

    switch PORTNUM for the port number. :) may be child pid, but gets you close enough to identify the problem app.