OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[linuxjm/LDP_man-pages.git] / original / man3 / get_nprocs_conf.3
1 .\" Copyright (c) 2012, Petr Benas
2 .\" and Copyright (c) 2012, Michael Kerrisk <mtk.man-pages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of
9 .\" this manual under the conditions for verbatim copying, provided that
10 .\" the entire resulting derived work is distributed under the terms of
11 .\" a permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume.
15 .\" no responsibility for errors or omissions, or for damages resulting.
16 .\" from the use of the information contained herein.  The author(s) may.
17 .\" not have taken the same level of care in the production of this.
18 .\" manual, which is licensed free of charge, as they might when working.
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23
24 .TH GET_NPROCS 3   2012-03-20 "GNU" "Linux Programmer's Manual"
25 .SH NAME
26 get_nprocs, get_nprocs_conf \- get number of processors
27 .SH SYNOPSIS
28 .B #include <sys/sysinfo.h>
29 .sp
30 .BI "int get_nprocs(void);"
31 .br
32 .BI "int get_nprocs_conf(void);"
33 .SH DESCRIPTION
34 The function
35 .BR get_nprocs_conf ()
36 returns the number of processors configured by the operating system.
37
38 The function
39 .BR get_nprocs ()
40 returns the number of processors currently available in the system.
41 This may be less than the number returned by
42 .BR get_nprocs_conf ()
43 because processors may be offline (e.g., on hotpluggable systems).
44 .SH RETURN VALUE
45 As given in DESCRIPTION.
46 .SH CONFORMING TO
47 These functions are GNU extensions.
48 .SH NOTES
49 The current
50 .\" glibc 2.15
51 implementation of these functions is rather expensive,
52 since they open and parse files in the
53 .I /sys
54 file system each time they are called.
55
56 The following
57 .BR sysconf (3)
58 calls make use of the functions documented on this page
59 to return the same information.
60 .nf
61
62     np = sysconf(_SC_NPROCESSORS_CONF);     /* processors configured */
63     np = sysconf(_SC_NPROCESSORS_ONLN);     /* processors available */
64 .fi
65 .SH EXAMPLE
66 The following example shows how
67 .BR get_nprocs ()
68 and
69 .BR get_nprocs_conf ()
70 can be used.
71
72 .nf
73 #include <stdio.h>
74 #include <sys/sysinfo.h>
75
76 int
77 main(int argc, char *argv[])
78 {
79     printf("This system has %d processors configured and "
80             "%d processors available.\\n",
81             get_nprocs_conf(), get_nprocs());
82     return 0;
83 }
84 .fi
85