]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/get_phys_pages.3
share/mk/: distcheck: Run 'check' after 'build'
[thirdparty/man-pages.git] / man3 / get_phys_pages.3
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 2019-03-06 "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 int get_phys_pages(void);
34 .B long int 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 cause of 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 These functions obtain the required information by scanning the
62 .I MemTotal
63 and
64 .I MemFree
65 fields of
66 .IR /proc/meminfo .
67 .PP
68 The following
69 .BR sysconf (3)
70 calls provide a portable means of obtaining the same information as the
71 functions described on this page.
72 .PP
73 .in +4n
74 .EX
75 total_pages = sysconf(_SC_PHYS_PAGES); /* total pages */
76 avl_pages = sysconf(_SC_AVPHYS_PAGES); /* available pages */
77 .EE
78 .in
79 .SH EXAMPLE
80 The following example shows how
81 .BR get_phys_pages ()
82 and
83 .BR get_avphys_pages ()
84 can be used.
85 .PP
86 .EX
87 #include <stdio.h>
88 #include <stdlib.h>
89 #include <sys/sysinfo.h>
90
91 int
92 main(int argc, char *argv[])
93 {
94 printf("This system has %ld pages of physical memory and "
95 "%ld pages of physical memory available.\en",
96 get_phys_pages(), get_avphys_pages());
97 exit(EXIT_SUCCESS);
98 }
99 .EE
100 .SH SEE ALSO
101 .BR sysconf (3)