views:

48

answers:

1

Are there any C APIs for fetching free memory, swap memory consumption and to fetch file handle count similar to statvfs for file system information instead of directly parsing the /proc file system?

+1  A: 

Are there any C APIs for fetching free memory, swap memory consumption and to fetch file handle count similar to statvfs for file system information instead of directly parsing the /proc file system?

Considering that official top, ps and lsof go to /proc for the information, I think not.

The information, its structure and interpretation is highly OS specific, thus unlikely to be covered by a standard. E.g. Linux essentially has no free memory indicator.

Additionally, maintenance of consistent internal counters might cause performance regressions (esp. on SMP/multi-core systems) in the highly critical code paths like virtual memory management. Ditto for the file descriptors. That's why it is an accepted compromise that it's rather user space monitoring applications who should make the extra effort to get the information in the most consistent fashion possible, while the kernel's critical code is kept lean and slim.

Dummy00001