Debian Codegraph @

upstream/debian-unstable/man3/get_phys_pages.3

raw
1 .\" Copyright 2015, William Woodruff <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH get_phys_pages 3 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 get_phys_pages, get_avphys_pages \- get total and available physical
9 page counts
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B "#include <sys/sysinfo.h>"
16 .P
17 .B long get_phys_pages(void);
18 .B long get_avphys_pages(void);
19 .fi
20 .SH DESCRIPTION
21 The function
22 .BR get_phys_pages ()
23 returns the total number of physical pages of memory available on the system.
24 .P
25 The function
26 .BR get_avphys_pages ()
27 returns the number of currently available physical pages of memory on the
28 system.
29 .SH RETURN VALUE
30 On success,
31 these functions return a nonnegative value as given in DESCRIPTION.
32 On failure, they return \-1 and set
33 .I errno
34 to indicate the error.
35 .SH ERRORS
36 .TP
37 .B ENOSYS
38 The system could not provide the required information
39 (possibly because the
40 .I /proc
41 filesystem was not mounted).
42 .SH STANDARDS
43 GNU.
44 .SH HISTORY
45 Before glibc 2.23,
46 these functions obtained the required information by scanning the
47 .I MemTotal
48 and
49 .I MemFree
50 fields of
51 .IR /proc/meminfo .
52 Since glibc 2.23,
53 these functions obtain the required information by calling
54 .BR sysinfo (2).
55 .SH NOTES
56 The following
57 .BR sysconf (3)
58 calls provide a portable means of obtaining the same information as the
59 functions described on this page.
60 .P
61 .in +4n
62 .EX
63 total_pages = sysconf(_SC_PHYS_PAGES); /* total pages */
64 avl_pages = sysconf(_SC_AVPHYS_PAGES); /* available pages */
65 .EE
66 .in
67 .SH EXAMPLES
68 The following example shows how
69 .BR get_phys_pages ()
70 and
71 .BR get_avphys_pages ()
72 can be used.
73 .P
74 .\" SRC BEGIN (get_phys_pages.c)
75 .EX
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <sys/sysinfo.h>
79 \&
80 int
81 main(void)
82 {
83 printf("This system has %ld pages of physical memory and "
84 "%ld pages of physical memory available.\[rs]n",
85 get_phys_pages(), get_avphys_pages());
86 exit(EXIT_SUCCESS);
87 }
88 .EE
89 .\" SRC END
90 .SH SEE ALSO
91 .BR sysconf (3)