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