1 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
2 .\" and Copyright (c) 2002 Michael Kerrisk
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" 2004-11-16 -- mtk: the getrlimit.2 page, which formerly included
7 .\" coverage of getrusage(2), has been split, so that the latter is
8 .\" now covered in its own getrusage.2. For older details of change
9 .\" history, etc., see getrlimit.2
11 .\" Modified 2004-11-16, mtk, Noted that the nonconformance
12 .\" when SIGCHLD is being ignored is fixed in 2.6.9.
13 .\" 2008-02-22, Sripathi Kodi <sripathik@in.ibm.com>: Document RUSAGE_THREAD
14 .\" 2008-05-25, mtk, clarify RUSAGE_CHILDREN + other clean-ups.
15 .\" 2010-05-24, Mark Hills <mark@pogo.org.uk>: Description of fields,
16 .\" document ru_maxrss
17 .\" 2010-05-24, mtk, enhanced description of various fields
19 .TH GETRUSAGE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
21 getrusage \- get resource usage
24 .RI ( libc ", " \-lc )
27 .B #include <sys/resource.h>
29 .BI "int getrusage(int " who ", struct rusage *" usage );
33 returns resource usage measures for
35 which can be one of the following:
38 Return resource usage statistics for the calling process,
39 which is the sum of resources used by all threads in the process.
42 Return resource usage statistics for all children of the
43 calling process that have terminated and been waited for.
44 These statistics will include the resources used by grandchildren,
45 and further removed descendants,
46 if all of the intervening descendants waited on their terminated children.
48 .BR RUSAGE_THREAD " (since Linux 2.6.26)"
49 Return resource usage statistics for the calling thread.
52 feature test macro must be defined (before including
55 in order to obtain the definition of this constant from
56 .IR <sys/resource.h> .
58 The resource usages are returned in the structure pointed to by
60 which has the following form:
65 struct timeval ru_utime; /* user CPU time used */
66 struct timeval ru_stime; /* system CPU time used */
67 long ru_maxrss; /* maximum resident set size */
68 long ru_ixrss; /* integral shared memory size */
69 long ru_idrss; /* integral unshared data size */
70 long ru_isrss; /* integral unshared stack size */
71 long ru_minflt; /* page reclaims (soft page faults) */
72 long ru_majflt; /* page faults (hard page faults) */
73 long ru_nswap; /* swaps */
74 long ru_inblock; /* block input operations */
75 long ru_oublock; /* block output operations */
76 long ru_msgsnd; /* IPC messages sent */
77 long ru_msgrcv; /* IPC messages received */
78 long ru_nsignals; /* signals received */
79 long ru_nvcsw; /* voluntary context switches */
80 long ru_nivcsw; /* involuntary context switches */
85 Not all fields are completed;
86 unmaintained fields are set to zero by the kernel.
87 (The unmaintained fields are provided for compatibility with other systems,
88 and because they may one day be supported on Linux.)
89 The fields are interpreted as follows:
92 This is the total amount of time spent executing in user mode,
95 structure (seconds plus microseconds).
98 This is the total amount of time spent executing in kernel mode,
101 structure (seconds plus microseconds).
103 .IR ru_maxrss " (since Linux 2.6.32)"
104 This is the maximum resident set size used (in kilobytes).
106 .BR RUSAGE_CHILDREN ,
107 this is the resident set size of the largest child, not the maximum
108 resident set size of the process tree.
110 .IR ru_ixrss " (unmaintained)"
111 This field is currently unused on Linux.
113 .\" this is the integral of the text segment memory consumption,
114 .\" expressed in kilobyte-seconds.
116 .IR ru_idrss " (unmaintained)"
117 This field is currently unused on Linux.
118 .\" On some systems, this is the integral of the data segment memory consumption,
119 .\" expressed in kilobyte-seconds.
121 .IR ru_isrss " (unmaintained)"
122 This field is currently unused on Linux.
123 .\" On some systems, this is the integral of the stack memory consumption,
124 .\" expressed in kilobyte-seconds.
127 The number of page faults serviced without any I/O activity; here
128 I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
129 the list of pages awaiting reallocation.
132 The number of page faults serviced that required I/O activity.
134 .IR ru_nswap " (unmaintained)"
135 This field is currently unused on Linux.
136 .\" On some systems, this is the number of swaps out of physical memory.
138 .IR ru_inblock " (since Linux 2.6.22)"
139 The number of times the filesystem had to perform input.
141 .IR ru_oublock " (since Linux 2.6.22)"
142 The number of times the filesystem had to perform output.
144 .IR ru_msgsnd " (unmaintained)"
145 This field is currently unused on Linux.
146 .\" On FreeBSD 6.2, this appears to measure messages sent over sockets
148 .\" this field records the number of messages sent over sockets.
150 .IR ru_msgrcv " (unmaintained)"
151 This field is currently unused on Linux.
152 .\" On FreeBSD 6.2, this appears to measure messages received over sockets
154 .\" this field records the number of messages received over sockets.
156 .IR ru_nsignals " (unmaintained)"
157 This field is currently unused on Linux.
158 .\" On some systems, this field records the number of signals received.
160 .IR ru_nvcsw " (since Linux 2.6)"
161 The number of times a context switch resulted due to a process
162 voluntarily giving up the processor before its time slice was
163 completed (usually to await availability of a resource).
165 .IR ru_nivcsw " (since Linux 2.6)"
166 The number of times a context switch resulted due to a higher
167 priority process becoming runnable or because the current process
168 exceeded its time slice.
170 On success, zero is returned.
171 On error, \-1 is returned, and
173 is set to indicate the error.
178 points outside the accessible address space.
184 For an explanation of the terms used in this section, see
192 Interface Attribute Value
195 T} Thread safety MT-Safe
201 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
204 but specifies only the fields
212 Resource usage metrics are preserved across an
215 In Linux kernel versions before 2.6.9, if the disposition of
219 then the resource usages of child processes
220 are automatically included in the value returned by
221 .BR RUSAGE_CHILDREN ,
222 although POSIX.1-2001 explicitly prohibits this.
223 This nonconformance is rectified in Linux 2.6.9 and later.
224 .\" See the description of getrusage() in XSH.
225 .\" A similar statement was also in SUSv2.
227 The structure definition shown at the start of this page
228 was taken from 4.3BSD Reno.
230 Ancient systems provided a
232 function with a similar purpose to
234 For backward compatibility, glibc (up until version 2.32) also provides
236 All new applications should be written using
238 (Since version 2.33, glibc no longer provides an
242 See also the description of
247 .BR clock_gettime (2),