1GET_PHYS_PAGES(3)          Linux Programmer's Manual         GET_PHYS_PAGES(3)
2
3
4

NAME

6       get_phys_pages,  get_avphys_pages  -  get  total and available physical
7       page counts
8

SYNOPSIS

10       #include <sys/sysinfo.h>
11
12       long get_phys_pages(void);
13       long get_avphys_pages(void);
14

DESCRIPTION

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

RETURN VALUE

23       On success, these functions return a nonnegative value as given in  DE‐
24       SCRIPTION.   On  failure,  they return -1 and set errno to indicate the
25       error.
26

ERRORS

28       ENOSYS The system could not provide the required information  (possibly
29              because the /proc filesystem was not mounted).
30

CONFORMING TO

32       These functions are GNU extensions.
33

NOTES

35       Before glibc 2.23, these functions obtained the required information by
36       scanning the MemTotal and MemFree fields of /proc/meminfo.  Since glibc
37       2.23,  these  functions obtain the required information by calling sys‐
38       info(2).
39
40       The following sysconf(3) calls provide a portable  means  of  obtaining
41       the same information as the functions described on this page.
42
43           total_pages = sysconf(_SC_PHYS_PAGES);    /* total pages */
44           avl_pages = sysconf(_SC_AVPHYS_PAGES);    /* available pages */
45

EXAMPLES

47       The following example shows how get_phys_pages() and get_avphys_pages()
48       can be used.
49
50       #include <stdio.h>
51       #include <stdlib.h>
52       #include <sys/sysinfo.h>
53
54       int
55       main(int argc, char *argv[])
56       {
57           printf("This system has %ld pages of physical memory and "
58                   "%ld pages of physical memory available.\n",
59                   get_phys_pages(), get_avphys_pages());
60           exit(EXIT_SUCCESS);
61       }
62

SEE ALSO

64       sysconf(3)
65

COLOPHON

67       This page is part of release 5.12 of the Linux  man-pages  project.   A
68       description  of  the project, information about reporting bugs, and the
69       latest    version    of    this    page,    can     be     found     at
70       https://www.kernel.org/doc/man-pages/.
71
72
73
74GNU                               2021-03-22                 GET_PHYS_PAGES(3)
Impressum