Debian Codegraph @

upstream/debian-trixie/man3/get_nprocs.3

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