1 .\" Copyright (c) 2012, Petr Benas
2 .\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of
9 .\" this manual under the conditions for verbatim copying, provided that
10 .\" the entire resulting derived work is distributed under the terms of
11 .\" a permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume.
15 .\" no responsibility for errors or omissions, or for damages resulting.
16 .\" from the use of the information contained herein. The author(s) may.
17 .\" not have taken the same level of care in the production of this.
18 .\" manual, which is licensed free of charge, as they might when working.
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH GET_NPROCS 3 2012-03-20 "GNU" "Linux Programmer's Manual"
26 get_nprocs, get_nprocs_conf \- get number of processors
28 .B #include <sys/sysinfo.h>
30 .BI "int get_nprocs(void);"
32 .BI "int get_nprocs_conf(void);"
35 .BR get_nprocs_conf ()
36 returns the number of processors configured by the operating system.
40 returns the number of processors currently available in the system.
41 This may be less than the number returned by
42 .BR get_nprocs_conf ()
43 because processors may be offline (e.g., on hotpluggable systems).
45 As given in DESCRIPTION.
47 These functions are GNU extensions.
51 implementation of these functions is rather expensive,
52 since they open and parse files in the
54 file system each time they are called.
58 calls make use of the functions documented on this page
59 to return the same information.
62 np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
63 np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
66 The following example shows how
69 .BR get_nprocs_conf ()
74 #include <sys/sysinfo.h>
77 main(int argc, char *argv[])
79 printf("This system has %d processors configured and "
80 "%d processors available.\\n",
81 get_nprocs_conf(), get_nprocs());