Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does the lsof command get its information on linux [closed]

Tags:

linux

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?

like image 367
Chinaxing Avatar asked May 28 '26 10:05

Chinaxing


1 Answers

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.

like image 195
rhoward Avatar answered May 31 '26 06:05

rhoward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!