]>
Commit | Line | Data |
---|---|---|
f9d28c34 | 1 | .\" Copyright (c) 2012, Petr Benas |
ebae66eb | 2 | .\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com> |
f9d28c34 | 3 | .\" |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
f9d28c34 BP |
5 | .\" Permission is granted to make and distribute verbatim copies of this |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of | |
10 | .\" this manual under the conditions for verbatim copying, provided that | |
11 | .\" the entire resulting derived work is distributed under the terms of | |
12 | .\" a permission notice identical to this one. | |
13 | .\" | |
14 | .\" Since the Linux kernel and libraries are constantly changing, this | |
62290181 SP |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume |
16 | .\" no responsibility for errors or omissions, or for damages resulting | |
17 | .\" from the use of the information contained herein. The author(s) may | |
18 | .\" not have taken the same level of care in the production of this | |
19 | .\" manual, which is licensed free of charge, as they might when working | |
f9d28c34 BP |
20 | .\" professionally. |
21 | .\" | |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
6fe07dbf | 25 | .\" |
9ba01802 | 26 | .TH GET_NPROCS 3 2019-03-06 "GNU" "Linux Programmer's Manual" |
f9d28c34 | 27 | .SH NAME |
ebae66eb | 28 | get_nprocs, get_nprocs_conf \- get number of processors |
f9d28c34 BP |
29 | .SH SYNOPSIS |
30 | .B #include <sys/sysinfo.h> | |
68e4db0a | 31 | .PP |
f9d28c34 BP |
32 | .BI "int get_nprocs(void);" |
33 | .br | |
34 | .BI "int get_nprocs_conf(void);" | |
35 | .SH DESCRIPTION | |
ebae66eb MK |
36 | The function |
37 | .BR get_nprocs_conf () | |
38 | returns the number of processors configured by the operating system. | |
847e0d88 | 39 | .PP |
f9d28c34 BP |
40 | The function |
41 | .BR get_nprocs () | |
42 | returns the number of processors currently available in the system. | |
ebae66eb | 43 | This may be less than the number returned by |
f9d28c34 | 44 | .BR get_nprocs_conf () |
ebae66eb MK |
45 | because processors may be offline (e.g., on hotpluggable systems). |
46 | .SH RETURN VALUE | |
47 | As given in DESCRIPTION. | |
08da409a ZL |
48 | .SH ATTRIBUTES |
49 | For an explanation of the terms used in this section, see | |
50 | .BR attributes (7). | |
51 | .TS | |
52 | allbox; | |
53 | lb lb lb | |
54 | l l l. | |
55 | Interface Attribute Value | |
56 | T{ | |
57 | .BR get_nprocs (), | |
58 | .br | |
59 | .BR get_nprocs_conf () | |
60 | T} Thread safety MT-Safe | |
61 | .TE | |
847e0d88 | 62 | .sp 1 |
ebae66eb MK |
63 | .SH CONFORMING TO |
64 | These functions are GNU extensions. | |
65 | .SH NOTES | |
66 | The current | |
67 | .\" glibc 2.15 | |
68 | implementation of these functions is rather expensive, | |
69 | since they open and parse files in the | |
70 | .I /sys | |
9ee4a2b6 | 71 | filesystem each time they are called. |
847e0d88 | 72 | .PP |
ebae66eb MK |
73 | The following |
74 | .BR sysconf (3) | |
75 | calls make use of the functions documented on this page | |
76 | to return the same information. | |
207050fa MK |
77 | .PP |
78 | .in +4n | |
79 | .EX | |
80 | np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */ | |
81 | np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */ | |
82 | .EE | |
83 | .in | |
f9d28c34 | 84 | .SH EXAMPLE |
ebae66eb | 85 | The following example shows how |
f9d28c34 BP |
86 | .BR get_nprocs () |
87 | and | |
88 | .BR get_nprocs_conf () | |
89 | can be used. | |
847e0d88 | 90 | .PP |
207050fa | 91 | .EX |
28d33f0e | 92 | #include <stdlib.h> |
f9d28c34 BP |
93 | #include <stdio.h> |
94 | #include <sys/sysinfo.h> | |
95 | ||
ebae66eb MK |
96 | int |
97 | main(int argc, char *argv[]) | |
f9d28c34 | 98 | { |
ebae66eb | 99 | printf("This system has %d processors configured and " |
d1a71985 | 100 | "%d processors available.\en", |
ebae66eb | 101 | get_nprocs_conf(), get_nprocs()); |
28d33f0e | 102 | exit(EXIT_SUCCESS); |
f9d28c34 | 103 | } |
207050fa | 104 | .EE |
c9cfbbe9 MK |
105 | .SH SEE ALSO |
106 | .BR nproc (1) |