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