The lsof command can list open files including network connections.
I think it should works just like the other system tools which gather information from the /proc/, /dev/ or /sys locations in the Linux filesystem.
But when I tried to find information about open files from these locations, I failed:
ls /proc/self/fd
ls /proc/net/tcp
ls /dev/fd/
How does lsof get this information?
I found that this lsof repository includes a guide to porting that has the following:
Lsof obtains data about open UNIX dialect files by reading the kernel's proc structure information, following it to the related user structure, then reading the open file structures stored (usually) in the user structure. Typically lsof uses the kernel memory devices, /dev/kmem, /dev/mem, etc. to read kernel data.
The document has quite a bit of information about how the program works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With