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