Finding a process ID given a socket and inode in Python 3
问题 /proc/net/tcp gives me a local address, port, and inode number for a socket (0.0.0.0:5432 and 9289, for example). I'd like to find the PID for a specific process, given the above information. It's possible to open every numbered folder in /proc, and then check symlinks for matching socket/inode numbers with a shell command like "$ sudo ls -l /proc/*/fd/ 2>/dev/null | grep socket". However, this seems more computationally expensive than necessary, since <5% of the processes on any given system