summaryrefslogtreecommitdiff
path: root/doc/procps_misc.3
blob: 2ebc178646d3b2e3f2c5a6d9c970feef77528ea5 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
.\" (C) Copyright 2020 Craig Small <csmall@dropbear.xyz>
.\"
.\" %%%LICENSE_START(LGPL_2.1+)
.\" This manual is free software; you can redistribute it and/or
.\" modify it under the terms of the GNU Lesser General Public
.\" License as published by the Free Software Foundation; either
.\" version 2.1 of the License, or (at your option) any later version.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
.\" Lesser General Public License for more details.
.\"
.\" You should have received a copy of the GNU Lesser General Public
.\" License along with this library; if not, write to the Free Software
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
.\" %%%LICENSE_END
.\"
.TH PROCPS_MISC 3 2020-12-21 "libproc-2"
.\" Please adjust this date whenever revising the manpage.
.\"
.SH NAME
procps_misc \- API to system information in the /proc filesystem
.SH SYNOPSIS
.nf
.B #include <proc/namespace.h>
.PP
.BI "int procps_ns_get_id(const char * " name ");"
.BI "const char *procps_ns_get_name(const int " id ");"
.BI "int procps_ns_read_pid(const int " pid ", struct procps_namespaces * " nsp ");"
.PP
.B #include <proc/sysinfo.h>
.PP
.B long procps_cpu_count(void);
.B long procps_hertz_get(void);
.BI "int procps_loadavg(double * " av1 ", double * " av5 ", double * " av15 ");"
.B unsigned int procps_pid_length(void);
.PP
.B #include <proc/uptime.h>
.PP
.BI "int procps_uptime(double * " uptime_secs ", double * " idle_secs ");"
.B char *procps_uptime_sprint(void);
.B char *procps_uptime_sprint_short(void);
.PP
.B #include <proc/version.h>
.PP
.B int procps_linux_version(void);
.sp
Link with \fI\-lprocps\fP.
.SH DESCRIPTION
This manual page describes the miscellaneous API functions of the
.B procps
library.

.BR procps_cpu_count ()
returns the number of CPUs that are currently online. On most systems returns
the value of
.BI sysconf( _SC_NPROCESSORS_ONLY )
or assumed to be \fI1\fR.

.BR procps_hertz_get ()
returns the number of clock ticks per second. On most systems returns the
value of
.BI sysconf( _SC_CLK_TCK )
or assumed to be \fI100\fR. Divide certain values returned in the
in the \fI/proc\fR filesystem by this value to convert from ticks to seconds.

.BR procps_loadavg ()
Fetches the system load average and puts the 1, 5 and 15 minute averages into
the locations in the given pointers. If the relevant pointer is \fINULL\fR then
.BR procps_loadavg ()
will not set that value.

.BR procps_pid_length ()
Returns the maximum string length for a PID on the system. For example, if the largest
possible PID value on was 123, then the length would be 3. If the file
\fI/proc/sys/kernel/pid_max\fR is unreadable, the value is assumed to be  \fI5\fR.

.BR procps_linux_version ()
returns the current Linux version as an integer. On non-Linux systems that
have an emulated proc filesystem this function returns the version of the
Linux emulation instead.
The Linux version consists of a triple of positive integers representing
the major, minor and patch versions of the kernel.
.PP
The library provides 3 macros for separating out the components.
.RS 4
.TP 1.2i
.BR LINUX_VERSION_MAJOR (ver)
Extract the major component from the given version integer.
.TP
.BR LINUX_VERSION_MINOR (ver)
Extract the minor component from the given version integer.
.TP
.BR LINUX_VERSION_PATCH (ver)
Extract the patch component from the given version integer.
.RE
.PP
To encode a given Linux version, such as using it to compare against the current
version, use the following macro:
.TP
.BI LINUX_VERSION( major , minor , patch )
.PP
.BR procps_uptime ()
returns the uptime and idle time of the system. Either the
\fIuptime_secs\fR or \fIidle_secs\fR can be \fBNULL\fR in which case that
variable will not be returned.

The \fBsprint\fR variety of the functions return a human-readable
string of the uptime and other statistics.

.BR procps_ns_get_id ()
finds the ID of the namespace for the given namespace name.

.BR procps_ns_get_name ()
finds the name of the namespace of the given integer ID.

.BR procps_ns_read_pid ()
puts the inodes for the namespaces of the given process into
the array pointed to \fInsp\fR.

.SH RETURN VALUE
For
.BR procps_cpu_count "() , " procps_hertz_get "() and " procps_pid_length ()
see the \fBDESCRIPTION\fR section for return values.

.BR procps_loadavg ()
returns 0 on success. On failure, it
returns a negative integer to one of the values defined below.
.TP
.B -ERANGE
Unable to parse the loadavg file.
.PP

.BR procps_linux_version ()
returns a positive integer encoding the Linux version if successful. Otherwise
returns a negative integer to one of the values defined below.
.TP
.B -EIO
The procps library was unable to read the osrelease file.
.TP
.B -ERANGE
Unable to parse the osrelease file.
.PP
.BR procps_linux_version ()
may also return any (negated) value that \fBfopen\fR() may set errno to.

.BR procps_ns_get_id ()
returns an integer for the namespace ID for the given name or
.B \-EINVAL
for an invalid input or an unknown namespace name.

.BR procps_ns_get_name ()
returns a statically allocated string containing the name of the
namespace for the given ID. If the name is not found the function
returns
.B NULL

.BR procps_ns_read_pid ()
Returns 0 on success and \fB\-EINVAL\fR on failure.

.BR procps_uptime ()
returns 0 on success. On failure, it
returns a negative integer to one of the values defined below.
.TP
.B -ERANGE
Unable to parse the uptime file.
.PP
.BR procps_uptime ()
may also return any (negated) value that \fBfopen\fR() may set errno to.

.BR procps_uptime_sprint_short ()
return a string from a statically allocated buffer which displays uptime.

.BR procps_uptime_sprint ()
also displays users and load average in the buffer. The formats are the
same as
.BR uptime (1)
with and without the
.B \-p
option.

.SH FILES
.TP
.I /proc/loadavg
The raw values for load average.
.TP
.I /proc/sys/kernel/osrelease
Contains the release version of the Linux kernel or proc filesystem.
.TP
.I /proc/sys/kernel/pid_max
Contains the value at which PIDs wrap around, one greater than the maximum PID value.
.TP
.I /proc/uptime
The raw values for uptime and idle time.
.TP
.IB /proc/ PID /ns
contains the set of namespaces for a particular \fBPID\fR.

.SH BUGS
Due to the way the three numbers are encoded into a single integer,
.BR procps_linux_version ()
and the associated macros assume 255 for the maximum value for the
minor and patch level and 32767 (hex 0x7fff) for the maximum value
for the major version. In other words, when Linux v 32768.0.0 comes
out, this function will break.
.\" Maj/6yr - In 7452 we'll think of something

.SH SEE ALSO
.BR uptime (1),
.BR fopen (3),
.BR sysconf (3),
.BR proc (5).