I have several applications that run on random ports. How would I take the pid or the file location and find which port it is running on?
Example of desired output:
www-data/apache = 80 my-awesome-game = 2023
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
In a similar way as netstat, lsof could also do the trick:
You'll have to grep the output for finding the PID you want.
The advantage I see using lsof is that '-p' in netstat doesn't work for all Unix flavors, I happen to manage AIX, Solaris and HP-UX (besides Red Hat) and use lsof cause all parameters are the same even though some features don't work as they should (i.e. having propietary and non-standard filesystems could cause trouble finding file names or other information).