]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
5ba917a9 AC |
2 | .\" Copyright (c) 2012, Petr Benas |
3 | .\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com> | |
4 | .\" | |
5 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft | |
6 | .\" | |
7 | .TH get_nprocs 3 (date) "Linux man-pages (unreleased)" | |
8 | .SH NAME | |
9 | get_nprocs, get_nprocs_conf \- get number of processors | |
10 | .SH LIBRARY | |
11 | Standard C library | |
12 | .RI ( libc ", " \-lc ) | |
13 | .SH SYNOPSIS | |
14 | .nf | |
15 | .B #include <sys/sysinfo.h> | |
16 | .PP | |
17 | .B int get_nprocs(void); | |
18 | .B int get_nprocs_conf(void); | |
19 | .fi | |
20 | .SH DESCRIPTION | |
21 | The function | |
22 | .BR get_nprocs_conf () | |
23 | returns the number of processors configured by the operating system. | |
24 | .PP | |
25 | The function | |
26 | .BR get_nprocs () | |
27 | returns the number of processors currently available in the system. | |
28 | This may be less than the number returned by | |
29 | .BR get_nprocs_conf () | |
30 | because processors may be offline (e.g., on hotpluggable systems). | |
31 | .SH RETURN VALUE | |
32 | As given in DESCRIPTION. | |
33 | .SH ATTRIBUTES | |
34 | For an explanation of the terms used in this section, see | |
35 | .BR attributes (7). | |
5ba917a9 AC |
36 | .TS |
37 | allbox; | |
38 | lbx lb lb | |
39 | l l l. | |
40 | Interface Attribute Value | |
41 | T{ | |
9e54434e BR |
42 | .na |
43 | .nh | |
5ba917a9 AC |
44 | .BR get_nprocs (), |
45 | .BR get_nprocs_conf () | |
46 | T} Thread safety MT-Safe | |
47 | .TE | |
5ba917a9 AC |
48 | .sp 1 |
49 | .SH STANDARDS | |
4131356c | 50 | GNU. |
5ba917a9 AC |
51 | .SH NOTES |
52 | The current | |
53 | .\" glibc 2.15 | |
54 | implementation of these functions is rather expensive, | |
55 | since they open and parse files in the | |
56 | .I /sys | |
57 | filesystem each time they are called. | |
58 | .PP | |
59 | The following | |
60 | .BR sysconf (3) | |
61 | calls make use of the functions documented on this page | |
62 | to return the same information. | |
63 | .PP | |
64 | .in +4n | |
65 | .EX | |
66 | np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */ | |
67 | np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */ | |
68 | .EE | |
69 | .in | |
70 | .SH EXAMPLES | |
71 | The following example shows how | |
72 | .BR get_nprocs () | |
73 | and | |
74 | .BR get_nprocs_conf () | |
75 | can be used. | |
76 | .PP | |
77 | .\" SRC BEGIN (get_nprocs_conf.c) | |
78 | .EX | |
79 | #include <stdio.h> | |
80 | #include <stdlib.h> | |
81 | #include <sys/sysinfo.h> | |
fe5dba13 | 82 | \& |
5ba917a9 AC |
83 | int |
84 | main(void) | |
85 | { | |
86 | printf("This system has %d processors configured and " | |
87 | "%d processors available.\en", | |
88 | get_nprocs_conf(), get_nprocs()); | |
89 | exit(EXIT_SUCCESS); | |
90 | } | |
91 | .EE | |
92 | .\" SRC END | |
93 | .SH SEE ALSO | |
94 | .BR nproc (1) |