1 .\" Copyright (c) 2012, Petr Benas
2 .\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of
10 .\" this manual under the conditions for verbatim copying, provided that
11 .\" the entire resulting derived work is distributed under the terms of
12 .\" a permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume
16 .\" no responsibility for errors or omissions, or for damages resulting
17 .\" from the use of the information contained herein. The author(s) may
18 .\" not have taken the same level of care in the production of this
19 .\" manual, which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH GET_NPROCS 3 2021-03-22 "GNU" "Linux Programmer's Manual"
28 get_nprocs, get_nprocs_conf \- get number of processors
31 .B #include <sys/sysinfo.h>
33 .BI "int get_nprocs(void);"
34 .BI "int get_nprocs_conf(void);"
38 .BR get_nprocs_conf ()
39 returns the number of processors configured by the operating system.
43 returns the number of processors currently available in the system.
44 This may be less than the number returned by
45 .BR get_nprocs_conf ()
46 because processors may be offline (e.g., on hotpluggable systems).
48 As given in DESCRIPTION.
50 For an explanation of the terms used in this section, see
58 Interface Attribute Value
61 .BR get_nprocs_conf ()
62 T} Thread safety MT-Safe
68 These functions are GNU extensions.
72 implementation of these functions is rather expensive,
73 since they open and parse files in the
75 filesystem each time they are called.
79 calls make use of the functions documented on this page
80 to return the same information.
84 np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
85 np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
89 The following example shows how
92 .BR get_nprocs_conf ()
98 #include <sys/sysinfo.h>
101 main(int argc, char *argv[])
103 printf("This system has %d processors configured and "
104 "%d processors available.\en",
105 get_nprocs_conf(), get_nprocs());