1get_phys_pages(3)          Library Functions 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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <sys/sysinfo.h>
14
15       long get_phys_pages(void);
16       long get_avphys_pages(void);
17

DESCRIPTION

19       The function get_phys_pages() returns  the  total  number  of  physical
20       pages of memory available on the system.
21
22       The  function get_avphys_pages() returns the number of currently avail‐
23       able physical pages of memory on the system.
24

RETURN VALUE

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

ERRORS

31       ENOSYS The system could not provide the required information  (possibly
32              because the /proc filesystem was not mounted).
33

STANDARDS

35       GNU.
36

HISTORY

38       Before glibc 2.23, these functions obtained the required information by
39       scanning the MemTotal and MemFree fields of /proc/meminfo.  Since glibc
40       2.23,  these  functions obtain the required information by calling sys‐
41       info(2).
42

NOTES

44       The following sysconf(3) calls provide a portable  means  of  obtaining
45       the same information as the functions described on this page.
46
47           total_pages = sysconf(_SC_PHYS_PAGES);    /* total pages */
48           avl_pages = sysconf(_SC_AVPHYS_PAGES);    /* available pages */
49

EXAMPLES

51       The following example shows how get_phys_pages() and get_avphys_pages()
52       can be used.
53
54       #include <stdio.h>
55       #include <stdlib.h>
56       #include <sys/sysinfo.h>
57
58       int
59       main(void)
60       {
61           printf("This system has %ld pages of physical memory and "
62                   "%ld pages of physical memory available.\n",
63                   get_phys_pages(), get_avphys_pages());
64           exit(EXIT_SUCCESS);
65       }
66

SEE ALSO

68       sysconf(3)
69
70
71
72Linux man-pages 6.05              2023-05-03                 get_phys_pages(3)
Impressum