I'm trying to implement code that enumerate all existing TCP connections per process (similar to netstat -lptn
).
I prefer to implement it myself and not to rely on netstat
.
In order to do that, I'm parsing data from /proc/<PID>/net/tcp
.
I saw that a number of TCP connections are listed under /proc/<PID>/net/tcp
but not listed by netstat -lptn
command.
For example I see that /proc/1/net/tcp
and /proc/2/net/tcp
have several TCP connections (tried on Ubuntu 16).
As I understand, /proc/1/net/tcp
is related to the /sbin/init
process which should not have any TCP connection.
The /proc/2/net/tcp
is related to kthreadd
which also should not have any TCP connection.