1 .\" Copyright (c) 2012, Petr Benas
2 .\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH GET_NPROCS 3 2021-03-22 "GNU" "Linux Programmer's Manual"
8 get_nprocs, get_nprocs_conf \- get number of processors
11 .RI ( libc ", " \-lc )
14 .B #include <sys/sysinfo.h>
16 .B int get_nprocs(void);
17 .B int get_nprocs_conf(void);
21 .BR get_nprocs_conf ()
22 returns the number of processors configured by the operating system.
26 returns the number of processors currently available in the system.
27 This may be less than the number returned by
28 .BR get_nprocs_conf ()
29 because processors may be offline (e.g., on hotpluggable systems).
31 As given in DESCRIPTION.
33 For an explanation of the terms used in this section, see
41 Interface Attribute Value
44 .BR get_nprocs_conf ()
45 T} Thread safety MT-Safe
51 These functions are GNU extensions.
55 implementation of these functions is rather expensive,
56 since they open and parse files in the
58 filesystem each time they are called.
62 calls make use of the functions documented on this page
63 to return the same information.
67 np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
68 np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
72 The following example shows how
75 .BR get_nprocs_conf ()
81 #include <sys/sysinfo.h>
84 main(int argc, char *argv[])
86 printf("This system has %d processors configured and "
87 "%d processors available.\en",
88 get_nprocs_conf(), get_nprocs());