seccomp_unotify.2: tfix
[man-pages.git] / man2 / getrusage.2
blob85c4ffed1c23e36da7fec84bc86f967b7f43bf7c
1 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
2 .\" and Copyright (c) 2002 Michael Kerrisk
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" 2004-11-16 -- mtk: the getrlimit.2 page, which formerly included
27 .\" coverage of getrusage(2), has been split, so that the latter is
28 .\" now covered in its own getrusage.2.  For older details of change
29 .\" history, etc., see getrlimit.2
30 .\"
31 .\" Modified 2004-11-16, mtk, Noted that the nonconformance
32 .\"     when SIGCHLD is being ignored is fixed in 2.6.9.
33 .\" 2008-02-22, Sripathi Kodi <sripathik@in.ibm.com>: Document RUSAGE_THREAD
34 .\" 2008-05-25, mtk, clarify RUSAGE_CHILDREN + other clean-ups.
35 .\" 2010-05-24, Mark Hills <mark@pogo.org.uk>: Description of fields,
36 .\"     document ru_maxrss
37 .\" 2010-05-24, mtk, enhanced description of various fields
38 .\"
39 .TH GETRUSAGE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
40 .SH NAME
41 getrusage \- get resource usage
42 .SH SYNOPSIS
43 .nf
44 .B #include <sys/resource.h>
45 .PP
46 .BI "int getrusage(int " who ", struct rusage *" usage );
47 .fi
48 .SH DESCRIPTION
49 .BR getrusage ()
50 returns resource usage measures for
51 .IR who ,
52 which can be one of the following:
53 .TP
54 .B RUSAGE_SELF
55 Return resource usage statistics for the calling process,
56 which is the sum of resources used by all threads in the process.
57 .TP
58 .B RUSAGE_CHILDREN
59 Return resource usage statistics for all children of the
60 calling process that have terminated and been waited for.
61 These statistics will include the resources used by grandchildren,
62 and further removed descendants,
63 if all of the intervening descendants waited on their terminated children.
64 .TP
65 .BR RUSAGE_THREAD " (since Linux 2.6.26)"
66 Return resource usage statistics for the calling thread.
67 The
68 .B _GNU_SOURCE
69 feature test macro must be defined (before including
70 .I any
71 header file)
72 in order to obtain the definition of this constant from
73 .IR <sys/resource.h> .
74 .PP
75 The resource usages are returned in the structure pointed to by
76 .IR usage ,
77 which has the following form:
78 .PP
79 .in +4n
80 .EX
81 struct rusage {
82     struct timeval ru_utime; /* user CPU time used */
83     struct timeval ru_stime; /* system CPU time used */
84     long   ru_maxrss;        /* maximum resident set size */
85     long   ru_ixrss;         /* integral shared memory size */
86     long   ru_idrss;         /* integral unshared data size */
87     long   ru_isrss;         /* integral unshared stack size */
88     long   ru_minflt;        /* page reclaims (soft page faults) */
89     long   ru_majflt;        /* page faults (hard page faults) */
90     long   ru_nswap;         /* swaps */
91     long   ru_inblock;       /* block input operations */
92     long   ru_oublock;       /* block output operations */
93     long   ru_msgsnd;        /* IPC messages sent */
94     long   ru_msgrcv;        /* IPC messages received */
95     long   ru_nsignals;      /* signals received */
96     long   ru_nvcsw;         /* voluntary context switches */
97     long   ru_nivcsw;        /* involuntary context switches */
99 .EE
102 Not all fields are completed;
103 unmaintained fields are set to zero by the kernel.
104 (The unmaintained fields are provided for compatibility with other systems,
105 and because they may one day be supported on Linux.)
106 The fields are interpreted as follows:
108 .I ru_utime
109 This is the total amount of time spent executing in user mode,
110 expressed in a
111 .I timeval
112 structure (seconds plus microseconds).
114 .I ru_stime
115 This is the total amount of time spent executing in kernel mode,
116 expressed in a
117 .I timeval
118 structure (seconds plus microseconds).
120 .IR ru_maxrss " (since Linux 2.6.32)"
121 This is the maximum resident set size used (in kilobytes).
123 .BR RUSAGE_CHILDREN ,
124 this is the resident set size of the largest child, not the maximum
125 resident set size of the process tree.
127 .IR ru_ixrss " (unmaintained)"
128 This field is currently unused on Linux.
129 .\" On some systems,
130 .\" this is the integral of the text segment memory consumption,
131 .\" expressed in kilobyte-seconds.
133 .IR ru_idrss " (unmaintained)"
134 This field is currently unused on Linux.
135 .\" On some systems, this is the integral of the data segment memory consumption,
136 .\" expressed in kilobyte-seconds.
138 .IR ru_isrss " (unmaintained)"
139 This field is currently unused on Linux.
140 .\" On some systems, this is the integral of the stack memory consumption,
141 .\" expressed in kilobyte-seconds.
143 .I ru_minflt
144 The number of page faults serviced without any I/O activity; here
145 I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
146 the list of pages awaiting reallocation.
148 .I ru_majflt
149 The number of page faults serviced that required I/O activity.
151 .IR ru_nswap  " (unmaintained)"
152 This field is currently unused on Linux.
153 .\" On some systems, this is the number of swaps out of physical memory.
155 .IR ru_inblock " (since Linux 2.6.22)"
156 The number of times the filesystem had to perform input.
158 .IR ru_oublock " (since Linux 2.6.22)"
159 The number of times the filesystem had to perform output.
161 .IR ru_msgsnd " (unmaintained)"
162 This field is currently unused on Linux.
163 .\" On FreeBSD 6.2, this appears to measure messages sent over sockets
164 .\" On some systems,
165 .\" this field records the number of messages sent over sockets.
167 .IR ru_msgrcv " (unmaintained)"
168 This field is currently unused on Linux.
169 .\" On FreeBSD 6.2, this appears to measure messages received over sockets
170 .\" On some systems,
171 .\" this field records the number of messages received over sockets.
173 .IR ru_nsignals " (unmaintained)"
174 This field is currently unused on Linux.
175 .\" On some systems, this field records the number of signals received.
177 .IR ru_nvcsw " (since Linux 2.6)"
178 The number of times a context switch resulted due to a process
179 voluntarily giving up the processor before its time slice was
180 completed (usually to await availability of a resource).
182 .IR ru_nivcsw " (since Linux 2.6)"
183 The number of times a context switch resulted due to a higher
184 priority process becoming runnable or because the current process
185 exceeded its time slice.
186 .SH RETURN VALUE
187 On success, zero is returned.
188 On error, \-1 is returned, and
189 .I errno
190 is set to indicate the error.
191 .SH ERRORS
193 .B EFAULT
194 .I usage
195 points outside the accessible address space.
197 .B EINVAL
198 .I who
199 is invalid.
200 .SH ATTRIBUTES
201 For an explanation of the terms used in this section, see
202 .BR attributes (7).
203 .ad l
206 allbox;
207 lbx lb lb
208 l l l.
209 Interface       Attribute       Value
211 .BR getrusage ()
212 T}      Thread safety   MT-Safe
216 .sp 1
217 .SH CONFORMING TO
218 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
219 POSIX.1 specifies
220 .BR getrusage (),
221 but specifies only the fields
222 .I ru_utime
224 .IR ru_stime .
226 .B RUSAGE_THREAD
227 is Linux-specific.
228 .SH NOTES
229 Resource usage metrics are preserved across an
230 .BR execve (2).
232 In Linux kernel versions before 2.6.9, if the disposition of
233 .B SIGCHLD
234 is set to
235 .B SIG_IGN
236 then the resource usages of child processes
237 are automatically included in the value returned by
238 .BR RUSAGE_CHILDREN ,
239 although POSIX.1-2001 explicitly prohibits this.
240 This nonconformance is rectified in Linux 2.6.9 and later.
241 .\" See the description of getrusage() in XSH.
242 .\" A similar statement was also in SUSv2.
244 The structure definition shown at the start of this page
245 was taken from 4.3BSD Reno.
247 Ancient systems provided a
248 .BR vtimes ()
249 function with a similar purpose to
250 .BR getrusage ().
251 For backward compatibility, glibc (up until version 2.32) also provides
252 .BR vtimes ().
253 All new applications should be written using
254 .BR getrusage ().
255 (Since version 2.33, glibc no longer provides an
256 .BR vtimes ()
257 implementation.)
259 See also the description of
260 .IR /proc/[pid]/stat
262 .BR proc (5).
263 .SH SEE ALSO
264 .BR clock_gettime (2),
265 .BR getrlimit (2),
266 .BR times (2),
267 .BR wait (2),
268 .BR wait4 (2),
269 .BR clock (3)