1GET_NPROCS(3)              Linux Programmer's Manual             GET_NPROCS(3)
2
3
4

NAME

6       get_nprocs, get_nprocs_conf - get number of processors
7

SYNOPSIS

9       #include <sys/sysinfo.h>
10
11       int get_nprocs(void);
12       int get_nprocs_conf(void);
13

DESCRIPTION

15       The function get_nprocs_conf() returns the number of processors config‐
16       ured by the operating system.
17
18       The function get_nprocs() returns the number  of  processors  currently
19       available  in the system.  This may be less than the number returned by
20       get_nprocs_conf() because processors may be offline (e.g., on  hotplug‐
21       gable systems).
22

RETURN VALUE

24       As given in DESCRIPTION.
25

ATTRIBUTES

27       For   an   explanation   of   the  terms  used  in  this  section,  see
28       attributes(7).
29
30       ┌──────────────────┬───────────────┬─────────┐
31Interface         Attribute     Value   
32       ├──────────────────┼───────────────┼─────────┤
33get_nprocs(),     │ Thread safety │ MT-Safe │
34get_nprocs_conf() │               │         │
35       └──────────────────┴───────────────┴─────────┘
36

CONFORMING TO

38       These functions are GNU extensions.
39

NOTES

41       The current implementation of  these  functions  is  rather  expensive,
42       since  they  open and parse files in the /sys filesystem each time they
43       are called.
44
45       The following sysconf(3) calls make use of the functions documented  on
46       this page to return the same information.
47
48           np = sysconf(_SC_NPROCESSORS_CONF);     /* processors configured */
49           np = sysconf(_SC_NPROCESSORS_ONLN);     /* processors available */
50

EXAMPLE

52       The  following example shows how get_nprocs() and get_nprocs_conf() can
53       be used.
54
55       #include <stdlib.h>
56       #include <stdio.h>
57       #include <sys/sysinfo.h>
58
59       int
60       main(int argc, char *argv[])
61       {
62           printf("This system has %d processors configured and "
63                   "%d processors available.\n",
64                   get_nprocs_conf(), get_nprocs());
65           exit(EXIT_SUCCESS);
66       }
67

SEE ALSO

69       nproc(1)
70

COLOPHON

72       This page is part of release 4.16 of the Linux  man-pages  project.   A
73       description  of  the project, information about reporting bugs, and the
74       latest    version    of    this    page,    can     be     found     at
75       https://www.kernel.org/doc/man-pages/.
76
77
78
79GNU                               2017-09-15                     GET_NPROCS(3)
Impressum