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