How to find full process arguments and associated listening ports?

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:

ss -lnptu | awk 'NR>1 { split($7,p,","); printf "Listen: "$5 " Command: "; system("ps --no-headers -o args p "p[2]); }'

All Sockets (will likely require some additional filtering due to sockets without process information in TIME_WAIT, etc):

ss -anptu state listening state established state connected state unconnected | grep -v TIME_WAIT | awk 'NR>1 { split($7,p,","); printf "Listen: "$5 " Command: "; system("ps --no-headers -o args p "p[2]); }'

 


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 extra split to further isolate the numeric PID from the joined format that ss returns (e.g. pid=1306 -> 1306). I also added the -ww flag to make ps output the full args:

ss -lnptu | awk 'NR>1 { split($7,p,","); split(p[2],pid,"="); printf "Listen: "$5 " Command: "; system("ps --no-headers -ww -o args p "pid[2]); }'