]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/get_nprocs_conf.3
dist.mk, All pages: .TH: Generate date at 'make dist'
[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.\"
5fbde956 4.\" SPDX-License-Identifier: Linux-man-pages-copyleft
6fe07dbf 5.\"
ab47278f 6.TH GET_NPROCS 3 (date) "Linux man-pages (unreleased)"
f9d28c34 7.SH NAME
ebae66eb 8get_nprocs, get_nprocs_conf \- get number of processors
42009080
AC
9.SH LIBRARY
10Standard C library
11.RI ( libc ", " \-lc )
f9d28c34 12.SH SYNOPSIS
c7db92b9 13.nf
f9d28c34 14.B #include <sys/sysinfo.h>
68e4db0a 15.PP
1ae6b2c7
AC
16.B int get_nprocs(void);
17.B int get_nprocs_conf(void);
c7db92b9 18.fi
f9d28c34 19.SH DESCRIPTION
ebae66eb
MK
20The function
21.BR get_nprocs_conf ()
22returns the number of processors configured by the operating system.
847e0d88 23.PP
f9d28c34
BP
24The function
25.BR get_nprocs ()
26returns the number of processors currently available in the system.
ebae66eb 27This may be less than the number returned by
f9d28c34 28.BR get_nprocs_conf ()
ebae66eb
MK
29because processors may be offline (e.g., on hotpluggable systems).
30.SH RETURN VALUE
31As given in DESCRIPTION.
08da409a
ZL
32.SH ATTRIBUTES
33For an explanation of the terms used in this section, see
34.BR attributes (7).
c466875e
MK
35.ad l
36.nh
08da409a
ZL
37.TS
38allbox;
c466875e 39lbx lb lb
08da409a
ZL
40l l l.
41Interface Attribute Value
42T{
43.BR get_nprocs (),
08da409a
ZL
44.BR get_nprocs_conf ()
45T} Thread safety MT-Safe
46.TE
c466875e
MK
47.hy
48.ad
847e0d88 49.sp 1
3113c7f3 50.SH STANDARDS
ebae66eb
MK
51These functions are GNU extensions.
52.SH NOTES
53The current
54.\" glibc 2.15
55implementation of these functions is rather expensive,
56since they open and parse files in the
57.I /sys
9ee4a2b6 58filesystem each time they are called.
847e0d88 59.PP
ebae66eb
MK
60The following
61.BR sysconf (3)
62calls make use of the functions documented on this page
63to return the same information.
207050fa
MK
64.PP
65.in +4n
66.EX
67np = sysconf(_SC_NPROCESSORS_CONF); /* processors configured */
68np = sysconf(_SC_NPROCESSORS_ONLN); /* processors available */
69.EE
70.in
a14af333 71.SH EXAMPLES
ebae66eb 72The following example shows how
f9d28c34
BP
73.BR get_nprocs ()
74and
75.BR get_nprocs_conf ()
76can be used.
847e0d88 77.PP
b0b6ab4e 78.\" SRC BEGIN (get_nprocs_conf.c)
207050fa 79.EX
f9d28c34 80#include <stdio.h>
ad3868f0 81#include <stdlib.h>
f9d28c34
BP
82#include <sys/sysinfo.h>
83
ebae66eb 84int
f1e39c1e 85main(void)
f9d28c34 86{
ebae66eb 87 printf("This system has %d processors configured and "
d1a71985 88 "%d processors available.\en",
ebae66eb 89 get_nprocs_conf(), get_nprocs());
28d33f0e 90 exit(EXIT_SUCCESS);
f9d28c34 91}
207050fa 92.EE
b0b6ab4e 93.\" SRC END
c9cfbbe9
MK
94.SH SEE ALSO
95.BR nproc (1)