What processes are using which ports on unix?

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.


netstat -l (assuming it comes with that version of UNIX)


netstat -pln

EDIT: linux only, on other UNIXes netstat may not support all these options.


Given (almost) everything on unix is a file, and lsof lists open files...

Linux : netstat -putan or lsof | grep TCP

OSX : lsof | grep TCP

Other Unixen : lsof way...

Tags:

Hp Ux