1GET_NPROCS(3) Linux Programmer's Manual GET_NPROCS(3)
2
3
4
6 get_nprocs, get_nprocs_conf - get number of processors
7
9 #include <sys/sysinfo.h>
10
11 int get_nprocs(void);
12 int get_nprocs_conf(void);
13
15 The function get_nprocs_conf() returns the number of processors config‐
16 ured by the operating system.
17
18 The function get_nprocs() returns the number of processors currently
19 available in the system. This may be less than the number returned by
20 get_nprocs_conf() because processors may be offline (e.g., on hotplug‐
21 gable systems).
22
24 As given in DESCRIPTION.
25
27 For an explanation of the terms used in this section, see at‐
28 tributes(7).
29
30 ┌────────────────────────────────────────────┬───────────────┬─────────┐
31 │Interface │ Attribute │ Value │
32 ├────────────────────────────────────────────┼───────────────┼─────────┤
33 │get_nprocs(), get_nprocs_conf() │ Thread safety │ MT-Safe │
34 └────────────────────────────────────────────┴───────────────┴─────────┘
35
37 These functions are GNU extensions.
38
40 The current implementation of these functions is rather expensive,
41 since they open and parse files in the /sys filesystem each time they
42 are called.
43
44 The following sysconf(3) calls make use of the functions documented on
45 this page to return the same information.
46
47 np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
48 np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
49
51 The following example shows how get_nprocs() and get_nprocs_conf() can
52 be used.
53
54 #include <stdlib.h>
55 #include <stdio.h>
56 #include <sys/sysinfo.h>
57
58 int
59 main(int argc, char *argv[])
60 {
61 printf("This system has %d processors configured and "
62 "%d processors available.\n",
63 get_nprocs_conf(), get_nprocs());
64 exit(EXIT_SUCCESS);
65 }
66
68 nproc(1)
69
71 This page is part of release 5.13 of the Linux man-pages project. A
72 description of the project, information about reporting bugs, and the
73 latest version of this page, can be found at
74 https://www.kernel.org/doc/man-pages/.
75
76
77
78GNU 2021-03-22 GET_NPROCS(3)