tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / get_nprocs.3
blobb34a77e03d06ff479bfdb5030616cc1a77345938
1 '\" t
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
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 .PP
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 .PP
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 .ad l
37 .nh
38 .TS
39 allbox;
40 lbx lb lb
41 l l l.
42 Interface       Attribute       Value
44 .BR get_nprocs (),
45 .BR get_nprocs_conf ()
46 T}      Thread safety   MT-Safe
47 .TE
48 .hy
49 .ad
50 .sp 1
51 .SH STANDARDS
52 These functions are GNU extensions.
53 .SH NOTES
54 The current
55 .\" glibc 2.15
56 implementation of these functions is rather expensive,
57 since they open and parse files in the
58 .I /sys
59 filesystem each time they are called.
60 .PP
61 The following
62 .BR sysconf (3)
63 calls make use of the functions documented on this page
64 to return the same information.
65 .PP
66 .in +4n
67 .EX
68 np = sysconf(_SC_NPROCESSORS_CONF);     /* processors configured */
69 np = sysconf(_SC_NPROCESSORS_ONLN);     /* processors available */
70 .EE
71 .in
72 .SH EXAMPLES
73 The following example shows how
74 .BR get_nprocs ()
75 and
76 .BR get_nprocs_conf ()
77 can be used.
78 .PP
79 .\" SRC BEGIN (get_nprocs_conf.c)
80 .EX
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <sys/sysinfo.h>
85 int
86 main(void)
88     printf("This system has %d processors configured and "
89             "%d processors available.\en",
90             get_nprocs_conf(), get_nprocs());
91     exit(EXIT_SUCCESS);
93 .EE
94 .\" SRC END
95 .SH SEE ALSO
96 .BR nproc (1)