Debian Codegraph @

upstream/debian-trixie/man3/get_phys_pages.3

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