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

int
main(void)
{
    printf("This system has %d processors configured and "
            "%d processors available.\en",
            get_nprocs_conf(), get_nprocs());
    exit(EXIT_SUCCESS);
}
.EE
.\" SRC END
.SH SEE ALSO
.BR nproc (1)