]>
Commit | Line | Data |
---|---|---|
178f0f6d WW |
1 | .\" Copyright (c) 2015 William Woodruff (william@tuffbizz.com) |
2 | .\" | |
5fbde956 | 3 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
178f0f6d | 4 | .\" |
45186a5d | 5 | .TH GET_PHYS_PAGES 3 2021-03-22 "Linux man-pages (unreleased)" |
178f0f6d | 6 | .SH NAME |
551b8ee1 MK |
7 | get_phys_pages, get_avphys_pages \- get total and available physical |
8 | page counts | |
42009080 AC |
9 | .SH LIBRARY |
10 | Standard C library | |
11 | .RI ( libc ", " \-lc ) | |
178f0f6d WW |
12 | .SH SYNOPSIS |
13 | .nf | |
14 | .B "#include <sys/sysinfo.h>" | |
68e4db0a | 15 | .PP |
9a84e338 AC |
16 | .B long get_phys_pages(void); |
17 | .B long get_avphys_pages(void); | |
3b3b8d5d | 18 | .fi |
178f0f6d WW |
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. | |
847e0d88 | 23 | .PP |
178f0f6d WW |
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 | |
551b8ee1 MK |
29 | On success, |
30 | these functions return a nonnegative value as given in DESCRIPTION. | |
178f0f6d WW |
31 | On failure, they return \-1 and set |
32 | .I errno | |
855d489a | 33 | to indicate the error. |
178f0f6d WW |
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). | |
3113c7f3 | 41 | .SH STANDARDS |
e878a2de MK |
42 | These functions are GNU extensions. |
43 | .SH NOTES | |
a6f73f75 AC |
44 | Before glibc 2.23, |
45 | these functions obtained the required information by scanning the | |
178f0f6d WW |
46 | .I MemTotal |
47 | and | |
48 | .I MemFree | |
49 | fields of | |
50 | .IR /proc/meminfo . | |
a6f73f75 AC |
51 | Since glibc 2.23, |
52 | these functions obtain the required information by calling | |
53 | .BR sysinfo (2). | |
847e0d88 | 54 | .PP |
178f0f6d WW |
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. | |
847e0d88 | 59 | .PP |
207050fa MK |
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 | |
a14af333 | 66 | .SH EXAMPLES |
178f0f6d WW |
67 | The following example shows how |
68 | .BR get_phys_pages () | |
69 | and | |
70 | .BR get_avphys_pages () | |
71 | can be used. | |
847e0d88 | 72 | .PP |
207050fa | 73 | .EX |
178f0f6d WW |
74 | #include <stdio.h> |
75 | #include <stdlib.h> | |
76 | #include <sys/sysinfo.h> | |
77 | ||
78 | int | |
79 | main(int argc, char *argv[]) | |
80 | { | |
81 | printf("This system has %ld pages of physical memory and " | |
d1a71985 | 82 | "%ld pages of physical memory available.\en", |
178f0f6d WW |
83 | get_phys_pages(), get_avphys_pages()); |
84 | exit(EXIT_SUCCESS); | |
85 | } | |
207050fa | 86 | .EE |
178f0f6d WW |
87 | .SH SEE ALSO |
88 | .BR sysconf (3) |