How to use lsof(List Opened Files) in a C/C++ application? How to use lsof(List Opened Files) in a C/C++ application? unix unix

How to use lsof(List Opened Files) in a C/C++ application?


Just open the files in /proc/net, like /proc/net/tcp, /proc/net/udp, etc. No need to slog through the lsof sources. :)


If you don't want to copy/paste or reimplement chunks of the lsof code, and it doesn't build any useful libraries you could leverage, you can still open a pipe to an lsof process and peruse its output.