1 .\" Copyright (c) 2015 William Woodruff (william@tuffbizz.com)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH GET_PHYS_PAGES 3 2021-03-22 "GNU" "Linux Programmer's Manual"
27 get_phys_pages, get_avphys_pages \- get total and available physical
31 .B "#include <sys/sysinfo.h>"
33 .B long get_phys_pages(void);
34 .B long get_avphys_pages(void);
39 returns the total number of physical pages of memory available on the system.
42 .BR get_avphys_pages ()
43 returns the number of currently available physical pages of memory on the
47 these functions return a nonnegative value as given in DESCRIPTION.
48 On failure, they return \-1 and set
50 to indicate the error.
54 The system could not provide the required information
57 filesystem was not mounted).
59 These functions are GNU extensions.
62 these functions obtained the required information by scanning the
69 these functions obtain the required information by calling
74 calls provide a portable means of obtaining the same information as the
75 functions described on this page.
79 total_pages = sysconf(_SC_PHYS_PAGES); /* total pages */
80 avl_pages = sysconf(_SC_AVPHYS_PAGES); /* available pages */
84 The following example shows how
87 .BR get_avphys_pages ()
93 #include <sys/sysinfo.h>
96 main(int argc, char *argv[])
98 printf("This system has %ld pages of physical memory and "
99 "%ld pages of physical memory available.\en",
100 get_phys_pages(), get_avphys_pages());