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