-
Notifications
You must be signed in to change notification settings - Fork 0
/
getrusage.html
351 lines (257 loc) · 10 KB
/
getrusage.html
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:26:24 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>GETRUSAGE</title>
</head>
<body>
<h1 align="center">GETRUSAGE</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#ATTRIBUTES">ATTRIBUTES</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">getrusage - get
resource usage</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/time.h> <br>
#include <sys/resource.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
getrusage(int</b> <i>who</i><b>, struct rusage
*</b><i>usage</i><b>);</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>getrusage</b>()
returns resource usage measures for <i>who</i>, which can be
one of the following: <b><br>
RUSAGE_SELF</b></p>
<p style="margin-left:22%;">Return resource usage
statistics for the calling process, which is the sum of
resources used by all threads in the process.</p>
<p style="margin-left:11%;"><b>RUSAGE_CHILDREN</b></p>
<p style="margin-left:22%;">Return resource usage
statistics for all children of the calling process that have
terminated and been waited for. These statistics will
include the resources used by grandchildren, and further
removed descendants, if all of the intervening descendants
waited on their terminated children.</p>
<p style="margin-left:11%;"><b>RUSAGE_THREAD</b> (since
Linux 2.6.26)</p>
<p style="margin-left:22%;">Return resource usage
statistics for the calling thread. The <b>_GNU_SOURCE</b>
feature test macro must be defined (before including
<i>any</i> header file) in order to obtain the definition of
this constant from <i><sys/resource.h></i>.</p>
<p style="margin-left:11%; margin-top: 1em">The resource
usages are returned in the structure pointed to by
<i>usage</i>, which has the following form:</p>
<p style="margin-left:17%; margin-top: 1em">struct rusage {
<br>
struct timeval ru_utime; /* user CPU time used */ <br>
struct timeval ru_stime; /* system CPU time used */ <br>
long ru_maxrss; /* maximum resident set size */ <br>
long ru_ixrss; /* integral shared memory size */ <br>
long ru_idrss; /* integral unshared data size */ <br>
long ru_isrss; /* integral unshared stack size */ <br>
long ru_minflt; /* page reclaims (soft page faults) */ <br>
long ru_majflt; /* page faults (hard page faults) */ <br>
long ru_nswap; /* swaps */ <br>
long ru_inblock; /* block input operations */ <br>
long ru_oublock; /* block output operations */ <br>
long ru_msgsnd; /* IPC messages sent */ <br>
long ru_msgrcv; /* IPC messages received */ <br>
long ru_nsignals; /* signals received */ <br>
long ru_nvcsw; /* voluntary context switches */ <br>
long ru_nivcsw; /* involuntary context switches */ <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">Not all fields
are completed; unmaintained fields are set to zero by the
kernel. (The unmaintained fields are provided for
compatibility with other systems, and because they may one
day be supported on Linux.) The fields are interpreted as
follows: <i><br>
ru_utime</i></p>
<p style="margin-left:22%;">This is the total amount of
time spent executing in user mode, expressed in a
<i>timeval</i> structure (seconds plus microseconds).</p>
<p style="margin-left:11%;"><i>ru_stime</i></p>
<p style="margin-left:22%;">This is the total amount of
time spent executing in kernel mode, expressed in a
<i>timeval</i> structure (seconds plus microseconds).</p>
<p style="margin-left:11%;"><i>ru_maxrss</i> (since Linux
2.6.32)</p>
<p style="margin-left:22%;">This is the maximum resident
set size used (in kilobytes). For <b>RUSAGE_CHILDREN</b>,
this is the resident set size of the largest child, not the
maximum resident set size of the process tree.</p>
<p style="margin-left:11%;"><i>ru_ixrss</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_idrss</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_isrss</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_minflt</i></p>
<p style="margin-left:22%;">The number of page faults
serviced without any I/O activity; here I/O activity is
avoided by “reclaiming” a page frame from the
list of pages awaiting reallocation.</p>
<p style="margin-left:11%;"><i>ru_majflt</i></p>
<p style="margin-left:22%;">The number of page faults
serviced that required I/O activity.</p>
<p style="margin-left:11%;"><i>ru_nswap</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_inblock</i> (since Linux
2.6.22)</p>
<p style="margin-left:22%;">The number of times the
filesystem had to perform input.</p>
<p style="margin-left:11%;"><i>ru_oublock</i> (since Linux
2.6.22)</p>
<p style="margin-left:22%;">The number of times the
filesystem had to perform output.</p>
<p style="margin-left:11%;"><i>ru_msgsnd</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_msgrcv</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_nsignals</i>
(unmaintained)</p>
<p style="margin-left:22%;">This field is currently unused
on Linux.</p>
<p style="margin-left:11%;"><i>ru_nvcsw</i> (since Linux
2.6)</p>
<p style="margin-left:22%;">The number of times a context
switch resulted due to a process voluntarily giving up the
processor before its time slice was completed (usually to
await availability of a resource).</p>
<p style="margin-left:11%;"><i>ru_nivcsw</i> (since Linux
2.6)</p>
<p style="margin-left:22%;">The number of times a context
switch resulted due to a higher priority process becoming
runnable or because the current process exceeded its time
slice.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
zero is returned. On error, -1 is returned, and <i>errno</i>
is set appropriately.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="76%">
<p style="margin-top: 1em"><i>usage</i> points outside the
accessible address space.</p></td>
<td width="2%">
</td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="76%">
<p><i>who</i> is invalid.</p></td>
<td width="2%">
</td></tr>
</table>
<h2>ATTRIBUTES
<a name="ATTRIBUTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">For an
explanation of the terms used in this section, see
<b>attributes</b>(7).</p>
<p align="center" style="margin-top: 1em"><img src="grohtml-521881.png" alt="Image grohtml-521881.png"></p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">POSIX.1-2001,
POSIX.1-2008, SVr4, 4.3BSD. POSIX.1 specifies
<b>getrusage</b>(), but specifies only the fields
<i>ru_utime</i> and <i>ru_stime</i>.</p>
<p style="margin-left:11%; margin-top: 1em"><b>RUSAGE_THREAD</b>
is Linux-specific.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Resource usage
metrics are preserved across an <b>execve</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">Including
<i><sys/time.h></i> is not required these days, but
increases portability. (Indeed, <i>struct timeval</i> is
defined in <i><sys/time.h></i>.)</p>
<p style="margin-left:11%; margin-top: 1em">In Linux kernel
versions before 2.6.9, if the disposition of <b>SIGCHLD</b>
is set to <b>SIG_IGN</b> then the resource usages of child
processes are automatically included in the value returned
by <b>RUSAGE_CHILDREN</b>, although POSIX.1-2001 explicitly
prohibits this. This nonconformance is rectified in Linux
2.6.9 and later.</p>
<p style="margin-left:11%; margin-top: 1em">The structure
definition shown at the start of this page was taken from
4.3BSD Reno.</p>
<p style="margin-left:11%; margin-top: 1em">Ancient systems
provided a <b>vtimes</b>() function with a similar purpose
to <b>getrusage</b>(). For backward compatibility, glibc
also provides <b>vtimes</b>(). All new applications should
be written using <b>getrusage</b>().</p>
<p style="margin-left:11%; margin-top: 1em">See also the
description of <i>/proc/[pid]/stat</i> in
<b>proc</b>(5).</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>clock_gettime</b>(2),
<b>getrlimit</b>(2), <b>times</b>(2), <b>wait</b>(2),
<b>wait4</b>(2), <b>clock</b>(3)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>