1GET_PHYS_PAGES(3) Linux Programmer's Manual GET_PHYS_PAGES(3)
2
3
4
6 get_phys_pages, get_avphys_pages - get total and available physical
7 page counts
8
10 #include <sys/sysinfo.h>
11
12 long int get_phys_pages(void);
13 long int get_avphys_pages(void);
14
16 The function get_phys_pages() returns the total number of physical
17 pages of memory available on the system.
18
19 The function get_avphys_pages() returns the number of currently avail‐
20 able physical pages of memory on the system.
21
23 On success, these functions return a nonnegative value as given in
24 DESCRIPTION. On failure, they return -1 and set errno to indicate the
25 cause of the error.
26
28 ENOSYS The system could not provide the required information (possibly
29 because the /proc filesystem was not mounted).
30
32 These functions are GNU extensions.
33
35 These functions obtain the required information by scanning the MemTo‐
36 tal and MemFree fields of /proc/meminfo.
37
38 The following sysconf(3) calls provide a portable means of obtaining
39 the same information as the functions described on this page.
40
41 total_pages = sysconf(_SC_PHYS_PAGES); /* total pages */
42 avl_pages = sysconf(_SC_AVPHYS_PAGES); /* available pages */
43
45 The following example shows how get_phys_pages() and get_avphys_pages()
46 can be used.
47
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <sys/sysinfo.h>
51
52 int
53 main(int argc, char *argv[])
54 {
55 printf("This system has %ld pages of physical memory and "
56 "%ld pages of physical memory available.\n",
57 get_phys_pages(), get_avphys_pages());
58 exit(EXIT_SUCCESS);
59 }
60
62 sysconf(3)
63
65 This page is part of release 5.04 of the Linux man-pages project. A
66 description of the project, information about reporting bugs, and the
67 latest version of this page, can be found at
68 https://www.kernel.org/doc/man-pages/.
69
70
71
72GNU 2019-03-06 GET_PHYS_PAGES(3)