mount_namespaces.7: SEE ALSO: add mount_setattr(2)
[man-pages.git] / man3 / get_phys_pages.3
blob31b55b4ca58983f89b94ee5e5b69d534dcd455f2
1 .\" Copyright (c) 2015 William Woodruff (william@tuffbizz.com)
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH GET_PHYS_PAGES 3  2021-03-22 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 get_phys_pages, get_avphys_pages \- get total and available physical
28 page counts
29 .SH SYNOPSIS
30 .nf
31 .B "#include <sys/sysinfo.h>"
32 .PP
33 .B long get_phys_pages(void);
34 .B long get_avphys_pages(void);
35 .fi
36 .SH DESCRIPTION
37 The function
38 .BR get_phys_pages ()
39 returns the total number of physical pages of memory available on the system.
40 .PP
41 The function
42 .BR get_avphys_pages ()
43 returns the number of currently available physical pages of memory on the
44 system.
45 .SH RETURN VALUE
46 On success,
47 these functions return a nonnegative value as given in DESCRIPTION.
48 On failure, they return \-1 and set
49 .I errno
50 to indicate the error.
51 .SH ERRORS
52 .TP
53 .B ENOSYS
54 The system could not provide the required information
55 (possibly because the
56 .I /proc
57 filesystem was not mounted).
58 .SH CONFORMING TO
59 These functions are GNU extensions.
60 .SH NOTES
61 Before glibc 2.23,
62 these functions obtained the required information by scanning the
63 .I MemTotal
64 and
65 .I MemFree
66 fields of
67 .IR /proc/meminfo .
68 Since glibc 2.23,
69 these functions obtain the required information by calling
70 .BR sysinfo (2).
71 .PP
72 The following
73 .BR sysconf (3)
74 calls provide a portable means of obtaining the same information as the
75 functions described on this page.
76 .PP
77 .in +4n
78 .EX
79 total_pages = sysconf(_SC_PHYS_PAGES);    /* total pages */
80 avl_pages = sysconf(_SC_AVPHYS_PAGES);    /* available pages */
81 .EE
82 .in
83 .SH EXAMPLES
84 The following example shows how
85 .BR get_phys_pages ()
86 and
87 .BR get_avphys_pages ()
88 can be used.
89 .PP
90 .EX
91 #include <stdio.h>
92 #include <stdlib.h>
93 #include <sys/sysinfo.h>
95 int
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());
101     exit(EXIT_SUCCESS);
104 .SH SEE ALSO
105 .BR sysconf (3)