1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
4 .\" and Copyright (c) 2002 Michael Kerrisk
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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
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
39 .TH GETRUSAGE 2 2010-06-14 "Linux" "Linux Programmer's Manual"
41 getrusage \- get resource usage
43 .B #include <sys/time.h>
45 .B #include <sys/resource.h>
47 .BI "int getrusage(int " who ", struct rusage *" usage );
51 returns resource usage measures for
53 which can be one of the following:
56 Return resource usage statistics for the calling process,
57 which is the sum of resources used by all threads in the process.
60 Return resource usage statistics for all children of the
61 calling process that have terminated and been waited for.
62 These statistics will include the resources used by grandchildren,
63 and further removed descendants,
64 if all of the intervening descendants waited on their terminated children.
66 .BR RUSAGE_THREAD " (since Linux 2.6.26)"
67 Return resource usage statistics for the calling thread.
69 The resource usages are returned in the structure pointed to by
71 which has the following form:
76 struct timeval ru_utime; /* user CPU time used */
77 struct timeval ru_stime; /* system CPU time used */
78 long ru_maxrss; /* maximum resident set size */
79 long ru_ixrss; /* integral shared memory size */
80 long ru_idrss; /* integral unshared data size */
81 long ru_isrss; /* integral unshared stack size */
82 long ru_minflt; /* page reclaims (soft page faults) */
83 long ru_majflt; /* page faults (hard page faults) */
84 long ru_nswap; /* swaps */
85 long ru_inblock; /* block input operations */
86 long ru_oublock; /* block output operations */
87 long ru_msgsnd; /* IPC messages sent */
88 long ru_msgrcv; /* IPC messages received */
89 long ru_nsignals; /* signals received */
90 long ru_nvcsw; /* voluntary context switches */
91 long ru_nivcsw; /* involuntary context switches */
96 Not all fields are completed;
97 unmaintained fields are set to zero by the kernel.
98 (The unmaintained fields are provided for compatibility with other systems,
99 and because they may one day be supported on Linux.)
100 The fields are interpreted as follows:
103 This is the total amount of time spent executing in user mode,
106 structure (seconds plus microseconds).
109 This is the total amount of time spent executing in kernel mode,
112 structure (seconds plus microseconds).
114 .IR ru_maxrss " (since Linux 2.6.32)"
115 This is the maximum resident set size used (in kilobytes). For
116 .BR RUSAGE_CHILDREN ,
117 this is the resident set size of the largest child, not the maximum
118 resident set size of the process tree.
120 .IR ru_ixrss " (unmaintained)"
121 This field is currently unused on Linux.
123 .\" this is the integral of the text segment memory consumption,
124 .\" expressed in kilobyte-seconds.
126 .IR ru_idrss " (unmaintained)"
127 This field is currently unused on Linux.
128 .\" On some systems, this is the integral of the data segment memory consumption,
129 .\" expressed in kilobyte-seconds.
131 .IR ru_isrss " (unmaintained)"
132 This field is currently unused on Linux.
133 .\" On some systems, this is the integral of the stack memory consumption,
134 .\" expressed in kilobyte-seconds.
137 The number of page faults serviced without any I/O activity; here
138 I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
139 the list of pages awaiting reallocation.
142 The number of page faults serviced that required I/O activity.
144 .IR ru_nswap " (unmaintained)"
145 This field is currently unused on Linux.
146 .\" On some systems, this is the number of swaps out of physical memory.
148 .IR ru_inblock " (since Linux 2.6.22)"
149 The number of times the file system had to perform input.
151 .IR ru_oublock " (since Linux 2.6.22)"
152 The number of times the file system had to perform output.
154 .IR ru_msgsnd " (unmaintained)"
155 This field is currently unused on Linux.
156 .\" On FreeBSD 6.2, this appears to measure messages sent over sockets
158 .\" this field records the number of messages sent over sockets.
160 .IR ru_msgrcv " (unmaintained)"
161 This field is currently unused on Linux.
162 .\" On FreeBSD 6.2, this appears to measure messages received over sockets
164 .\" this field records the number of messages received over sockets.
166 .IR ru_nsignals " (unmaintained)"
167 This field is currently unused on Linux.
168 .\" On some systems, this field records the number of signals received.
170 .IR ru_nvcsw " (since Linux 2.6)"
171 The number of times a context switch resulted due to a process
172 voluntarily giving up the processor before its time slice was
173 completed (usually to await availability of a resource).
175 .IR ru_nivcsw " (since Linux 2.6)"
176 The number of times a context switch resulted due to a higher
177 priority process becoming runnable or because the current process
178 exceeded its time slice.
181 On success, zero is returned.
182 On error, \-1 is returned, and
184 is set appropriately.
189 points outside the accessible address space.
196 POSIX.1-2001 specifies
198 but only specifies the fields
206 Resource usage metrics are preserved across an
211 is not required these days, but increases portability.
217 In Linux kernel versions before 2.6.9, if the disposition of
221 then the resource usages of child processes
222 are automatically included in the value returned by
223 .BR RUSAGE_CHILDREN ,
224 although POSIX.1-2001 explicitly prohibits this.
225 This nonconformance is rectified in Linux 2.6.9 and later.
226 .\" See the description of getrusage() in XSH.
227 .\" A similar statement was also in SUSv2.
229 The structure definition shown at the start of this page
230 was taken from 4.3BSD Reno.
232 See also the description of
237 .BR clock_gettime (2),