|
NAMEsg_get_mem_stats, sg_get_mem_stats_r, sg_free_mem_stats, sg_get_swap_stats, sg_get_swap_stats_r, sg_free_swap_stats - get VM statisticsSYNOPSIS#include <statgrab.h>
DESCRIPTIONMemory statistics are accessed through the sg_get_mem_stats() function and the sg_get_mem_stats_r() function. Both return a pointer to a sg_mem_stats buffer. Note that this statistic doesn't need to map the entire physical memory usage, it represents the real memory usable by the operating system.Memory statistics are accessed through the sg_get_swap_stats() function and the sg_get_swap_stats_r() function. Both return a pointer to a sg_swap_stats buffer. API Shortcut
The sg_mem_stats buffer received from sg_get_mem_stats_r() and the sg_swap_stats buffer received from sg_get_swap_stats_r() must be freed using sg_free_mem_stats() or the sg_free_swap_stats(), respectively, when not needed any more. The caller is responsible for doing it. On the FreeBSD operating system elevated privileges are required to access the swap statistics. Making the program setgid kmem should be sufficient. Programs running as root will not have this problem. RETURN VALUESThe VM system calls can return a pointer to either a sg_mem_stats or a sg_swap_stats.typedef struct{ unsigned long long total; unsigned long long free; unsigned long long used; unsigned long long cache; time_t systime; } sg_mem_stats;
typedef struct { unsigned long long total; unsigned long long used; unsigned long long free; time_t systime; } sg_swap_stats;
TODOAdd a function to hold open the file descriptor to the kernel memory structures. Doing this would allow the elevated privileges to be dropped early on.SEE ALSOstatgrab(3)WEBSITE⟨https://libstatgrab.org/⟩
Visit the GSP FreeBSD Man Page Interface. |