]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/get_nprocs_conf.3
getlogin.3: ffix
[thirdparty/man-pages.git] / man3 / get_nprocs_conf.3
CommitLineData
f9d28c34 1.\" Copyright (c) 2012, Petr Benas
ebae66eb 2.\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com>
f9d28c34 3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
f9d28c34
BP
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.
8.\"
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.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
62290181
SP
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
f9d28c34
BP
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
6fe07dbf 25.\"
bffbb22f 26.TH GET_NPROCS 3 2020-06-09 "GNU" "Linux Programmer's Manual"
f9d28c34 27.SH NAME
ebae66eb 28get_nprocs, get_nprocs_conf \- get number of processors
f9d28c34 29.SH SYNOPSIS
c7db92b9 30.nf
f9d28c34 31.B #include <sys/sysinfo.h>
68e4db0a 32.PP
f9d28c34 33.BI "int get_nprocs(void);"
f9d28c34 34.BI "int get_nprocs_conf(void);"
c7db92b9 35.fi
f9d28c34 36.SH DESCRIPTION
ebae66eb
MK
37The function
38.BR get_nprocs_conf ()
39returns the number of processors configured by the operating system.
847e0d88 40.PP
f9d28c34
BP
41The function
42.BR get_nprocs ()
43returns the number of processors currently available in the system.
ebae66eb 44This may be less than the number returned by
f9d28c34 45.BR get_nprocs_conf ()
ebae66eb
MK
46because processors may be offline (e.g., on hotpluggable systems).
47.SH RETURN VALUE
48As given in DESCRIPTION.
08da409a
ZL
49.SH ATTRIBUTES
50For an explanation of the terms used in this section, see
51.BR attributes (7).
52.TS
53allbox;
54lb lb lb
55l l l.
56Interface Attribute Value
57T{
58.BR get_nprocs (),
59.br
60.BR get_nprocs_conf ()
61T} Thread safety MT-Safe
62.TE
847e0d88 63.sp 1
ebae66eb
MK
64.SH CONFORMING TO
65These functions are GNU extensions.
66.SH NOTES
67The current
68.\" glibc 2.15
69implementation of these functions is rather expensive,
70since they open and parse files in the
71.I /sys
9ee4a2b6 72filesystem each time they are called.
847e0d88 73.PP
ebae66eb
MK
74The following
75.BR sysconf (3)
76calls make use of the functions documented on this page
77to return the same information.
207050fa
MK
78.PP
79.in +4n
80.EX
81np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
82np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
83.EE
84.in
a14af333 85.SH EXAMPLES
ebae66eb 86The following example shows how
f9d28c34
BP
87.BR get_nprocs ()
88and
89.BR get_nprocs_conf ()
90can be used.
847e0d88 91.PP
207050fa 92.EX
28d33f0e 93#include <stdlib.h>
f9d28c34
BP
94#include <stdio.h>
95#include <sys/sysinfo.h>
96
ebae66eb
MK
97int
98main(int argc, char *argv[])
f9d28c34 99{
ebae66eb 100 printf("This system has %d processors configured and "
d1a71985 101 "%d processors available.\en",
ebae66eb 102 get_nprocs_conf(), get_nprocs());
28d33f0e 103 exit(EXIT_SUCCESS);
f9d28c34 104}
207050fa 105.EE
c9cfbbe9
MK
106.SH SEE ALSO
107.BR nproc (1)