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