]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/get_phys_pages.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / get_phys_pages.3
CommitLineData
178f0f6d
WW
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.\"
9ba01802 25.TH GET_PHYS_PAGES 3 2019-03-06 "GNU" "Linux Programmer's Manual"
178f0f6d 26.SH NAME
551b8ee1
MK
27get_phys_pages, get_avphys_pages \- get total and available physical
28page counts
178f0f6d
WW
29.SH SYNOPSIS
30.nf
31.B "#include <sys/sysinfo.h>"
68e4db0a 32.PP
178f0f6d 33.B long int get_phys_pages(void);
1f11ec0b 34.B long int get_avphys_pages(void);
3b3b8d5d 35.fi
178f0f6d
WW
36.SH DESCRIPTION
37The function
38.BR get_phys_pages ()
39returns the total number of physical pages of memory available on the system.
847e0d88 40.PP
178f0f6d
WW
41The function
42.BR get_avphys_pages ()
43returns the number of currently available physical pages of memory on the
44system.
45.SH RETURN VALUE
551b8ee1
MK
46On success,
47these functions return a nonnegative value as given in DESCRIPTION.
178f0f6d
WW
48On failure, they return \-1 and set
49.I errno
50to indicate the cause of the error.
51.SH ERRORS
52.TP
53.B ENOSYS
54The system could not provide the required information
55(possibly because the
56.I /proc
57filesystem was not mounted).
58.SH CONFORMING TO
59These functions are GNU extensions.
60.SH NOTES
61These functions obtain the required information by scanning the
62.I MemTotal
63and
64.I MemFree
65fields of
66.IR /proc/meminfo .
847e0d88 67.PP
178f0f6d
WW
68The following
69.BR sysconf (3)
70calls provide a portable means of obtaining the same information as the
71functions described on this page.
847e0d88 72.PP
207050fa
MK
73.in +4n
74.EX
75total_pages = sysconf(_SC_PHYS_PAGES); /* total pages */
76avl_pages = sysconf(_SC_AVPHYS_PAGES); /* available pages */
77.EE
78.in
a14af333 79.SH EXAMPLES
178f0f6d
WW
80The following example shows how
81.BR get_phys_pages ()
82and
83.BR get_avphys_pages ()
84can be used.
847e0d88 85.PP
207050fa 86.EX
178f0f6d
WW
87#include <stdio.h>
88#include <stdlib.h>
89#include <sys/sysinfo.h>
90
91int
92main(int argc, char *argv[])
93{
94 printf("This system has %ld pages of physical memory and "
d1a71985 95 "%ld pages of physical memory available.\en",
178f0f6d
WW
96 get_phys_pages(), get_avphys_pages());
97 exit(EXIT_SUCCESS);
98}
207050fa 99.EE
178f0f6d
WW
100.SH SEE ALSO
101.BR sysconf (3)