1get_nprocs(3) Library Functions Manual get_nprocs(3)
2
3
4
6 get_nprocs, get_nprocs_conf - get number of processors
7
9 Standard C library (libc, -lc)
10
12 #include <sys/sysinfo.h>
13
14 int get_nprocs(void);
15 int get_nprocs_conf(void);
16
18 The function get_nprocs_conf() returns the number of processors config‐
19 ured by the operating system.
20
21 The function get_nprocs() returns the number of processors currently
22 available in the system. This may be less than the number returned by
23 get_nprocs_conf() because processors may be offline (e.g., on hotplug‐
24 gable systems).
25
27 As given in DESCRIPTION.
28
30 For an explanation of the terms used in this section, see at‐
31 tributes(7).
32
33 ┌────────────────────────────────────────────┬───────────────┬─────────┐
34 │Interface │ Attribute │ Value │
35 ├────────────────────────────────────────────┼───────────────┼─────────┤
36 │get_nprocs(), get_nprocs_conf() │ Thread safety │ MT-Safe │
37 └────────────────────────────────────────────┴───────────────┴─────────┘
38
40 GNU.
41
43 The current implementation of these functions is rather expensive,
44 since they open and parse files in the /sys filesystem each time they
45 are called.
46
47 The following sysconf(3) calls make use of the functions documented on
48 this page to return the same information.
49
50 np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
51 np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
52
54 The following example shows how get_nprocs() and get_nprocs_conf() can
55 be used.
56
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <sys/sysinfo.h>
60
61 int
62 main(void)
63 {
64 printf("This system has %d processors configured and "
65 "%d processors available.\n",
66 get_nprocs_conf(), get_nprocs());
67 exit(EXIT_SUCCESS);
68 }
69
71 nproc(1)
72
73
74
75Linux man-pages 6.05 2023-07-20 get_nprocs(3)