I can execute netstat -atulpn | grep java
to find all Java processes with their accompanying ports, which is great, however I would like to also have the processes full execution arguments also shown. I don't believe that this is possible with netstat
from everything I've explored so far and so I was thinking that I would have to write a script to process the output of netstat
and then pass the pids into ps
and then prettify the output to show the ip+port and full command line.
Is there a better way of doing this or is this about the only option?
ss -lnptu piped to awk with a call to ps -p. I'm on a mobile device, so it is a little tricky to type out a full example at the moment.
Listening Sockets:
All Sockets (will likely require some additional filtering due to sockets without process information in TIME_WAIT, etc):
I was getting errors from
ps
on Ubuntu 16.04 when using Mark Sturgill's answer as-is. Needed a slight modification to make it work: basically added an extrasplit
to further isolate the numeric PID from the joined format thatss
returns (e.g.pid=1306 -> 1306
). I also added the-ww
flag to make ps output the full args:@ylluminate, for CentOS change it to
ss -lnptu | awk 'NR>1 { split($6,p,","); printf "Listen: "$4 " Command: "; system("ps --no-headers -o args p "p[2]); }'