diff options
Diffstat (limited to 'man3/get_phys_pages.3')
-rw-r--r-- | man3/get_phys_pages.3 | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/man3/get_phys_pages.3 b/man3/get_phys_pages.3 new file mode 100644 index 0000000..71cd4c9 --- /dev/null +++ b/man3/get_phys_pages.3 @@ -0,0 +1,90 @@ +.\" Copyright (c) 2015 William Woodruff (william@tuffbizz.com) +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH get_phys_pages 3 2023-05-03 "Linux man-pages 6.05.01" +.SH NAME +get_phys_pages, get_avphys_pages \- get total and available physical +page counts +.SH LIBRARY +Standard C library +.RI ( libc ", " \-lc ) +.SH SYNOPSIS +.nf +.B "#include <sys/sysinfo.h>" +.PP +.B long get_phys_pages(void); +.B long get_avphys_pages(void); +.fi +.SH DESCRIPTION +The function +.BR get_phys_pages () +returns the total number of physical pages of memory available on the system. +.PP +The function +.BR get_avphys_pages () +returns the number of currently available physical pages of memory on the +system. +.SH RETURN VALUE +On success, +these functions return a nonnegative value as given in DESCRIPTION. +On failure, they return \-1 and set +.I errno +to indicate the error. +.SH ERRORS +.TP +.B ENOSYS +The system could not provide the required information +(possibly because the +.I /proc +filesystem was not mounted). +.SH STANDARDS +GNU. +.SH HISTORY +Before glibc 2.23, +these functions obtained the required information by scanning the +.I MemTotal +and +.I MemFree +fields of +.IR /proc/meminfo . +Since glibc 2.23, +these functions obtain the required information by calling +.BR sysinfo (2). +.SH NOTES +The following +.BR sysconf (3) +calls provide a portable means of obtaining the same information as the +functions described on this page. +.PP +.in +4n +.EX +total_pages = sysconf(_SC_PHYS_PAGES); /* total pages */ +avl_pages = sysconf(_SC_AVPHYS_PAGES); /* available pages */ +.EE +.in +.SH EXAMPLES +The following example shows how +.BR get_phys_pages () +and +.BR get_avphys_pages () +can be used. +.PP +.\" SRC BEGIN (get_phys_pages.c) +.EX +#include <stdio.h> +#include <stdlib.h> +#include <sys/sysinfo.h> +\& +int +main(void) +{ + printf("This system has %ld pages of physical memory and " + "%ld pages of physical memory available.\en", + get_phys_pages(), get_avphys_pages()); + exit(EXIT_SUCCESS); +} +.EE +.\" SRC END +.SH SEE ALSO +.BR sysconf (3) |