How to do like “netstat -p”, but faster?
问题 Both "netstat -p" and "lsof -n -i -P" seems to readlinking all processes fd's, like stat /proc/*/fd/* . How to do it more efficiently? My program wants to know what process is connecting to it. Traversing all processes again and again seems too ineffective. Ways suggesting iptables things or kernel patches are welcome too. 回答1: Take a look at this answer, where various methods and programs that perform socket to process mappings are mentioned. You might also try several additional techniques