]>
Commit | Line | Data |
---|---|---|
e3a887db | 1 | .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992 |
6883b3e7 | 2 | .\" and Copyright (c) 2002 Michael Kerrisk |
e3a887db | 3 | .\" |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
e3a887db MK |
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. | |
c13182ef | 13 | .\" |
e3a887db MK |
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. | |
c13182ef | 21 | .\" |
e3a887db MK |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
e3a887db | 25 | .\" |
c13182ef MK |
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 | |
0967c11f | 29 | .\" history, etc., see getrlimit.2 |
e3a887db | 30 | .\" |
cfea5132 | 31 | .\" Modified 2004-11-16, mtk, Noted that the nonconformance |
e3a887db | 32 | .\" when SIGCHLD is being ignored is fixed in 2.6.9. |
94ce95ef MK |
33 | .\" 2008-02-22, Sripathi Kodi <sripathik@in.ibm.com>: Document RUSAGE_THREAD |
34 | .\" 2008-05-25, mtk, clarify RUSAGE_CHILDREN + other clean-ups. | |
e3f4bf3e MK |
35 | .\" 2010-05-24, Mark Hills <mark@pogo.org.uk>: Description of fields, |
36 | .\" document ru_maxrss | |
57440a98 | 37 | .\" 2010-05-24, mtk, enhanced description of various fields |
e3a887db | 38 | .\" |
4b8c67d9 | 39 | .TH GETRUSAGE 2 2017-09-15 "Linux" "Linux Programmer's Manual" |
e3a887db MK |
40 | .SH NAME |
41 | getrusage \- get resource usage | |
42 | .SH SYNOPSIS | |
43 | .B #include <sys/time.h> | |
44 | .br | |
45 | .B #include <sys/resource.h> | |
68e4db0a | 46 | .PP |
e3a887db MK |
47 | .BI "int getrusage(int " who ", struct rusage *" usage ); |
48 | .SH DESCRIPTION | |
49 | .PP | |
50 | .BR getrusage () | |
94ce95ef MK |
51 | returns resource usage measures for |
52 | .IR who , | |
53 | which can be one of the following: | |
54 | .TP | |
2914a14d MK |
55 | .B RUSAGE_SELF |
56 | Return resource usage statistics for the calling process, | |
94ce95ef MK |
57 | which is the sum of resources used by all threads in the process. |
58 | .TP | |
2914a14d | 59 | .B RUSAGE_CHILDREN |
94ce95ef MK |
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. | |
65 | .TP | |
66 | .BR RUSAGE_THREAD " (since Linux 2.6.26)" | |
67 | Return resource usage statistics for the calling thread. | |
1205c845 MK |
68 | The |
69 | .B _GNU_SOURCE | |
70 | feature test macro must be defined (before including | |
71 | .I any | |
72 | header file) | |
73 | in order to obtain the definition of this constant from | |
74 | .IR <sys/resource.h> . | |
94ce95ef MK |
75 | .PP |
76 | The resource usages are returned in the structure pointed to by | |
77 | .IR usage , | |
78 | which has the following form: | |
c13182ef | 79 | .PP |
a08ea57c | 80 | .in +4n |
03bd5415 | 81 | .EX |
e3a887db | 82 | struct rusage { |
57440a98 MK |
83 | struct timeval ru_utime; /* user CPU time used */ |
84 | struct timeval ru_stime; /* system CPU time used */ | |
e3a887db MK |
85 | long ru_maxrss; /* maximum resident set size */ |
86 | long ru_ixrss; /* integral shared memory size */ | |
87 | long ru_idrss; /* integral unshared data size */ | |
88 | long ru_isrss; /* integral unshared stack size */ | |
57440a98 MK |
89 | long ru_minflt; /* page reclaims (soft page faults) */ |
90 | long ru_majflt; /* page faults (hard page faults) */ | |
e3a887db MK |
91 | long ru_nswap; /* swaps */ |
92 | long ru_inblock; /* block input operations */ | |
93 | long ru_oublock; /* block output operations */ | |
57440a98 MK |
94 | long ru_msgsnd; /* IPC messages sent */ |
95 | long ru_msgrcv; /* IPC messages received */ | |
e3a887db MK |
96 | long ru_nsignals; /* signals received */ |
97 | long ru_nvcsw; /* voluntary context switches */ | |
98 | long ru_nivcsw; /* involuntary context switches */ | |
99 | }; | |
03bd5415 | 100 | .EE |
a08ea57c | 101 | .in |
d1cd1e05 | 102 | .PP |
14f1e036 MK |
103 | Not all fields are completed; |
104 | unmaintained fields are set to zero by the kernel. | |
105 | (The unmaintained fields are provided for compatibility with other systems, | |
106 | and because they may one day be supported on Linux.) | |
107 | The fields are interpreted as follows: | |
d1cd1e05 MH |
108 | .TP |
109 | .I ru_utime | |
57440a98 MK |
110 | This is the total amount of time spent executing in user mode, |
111 | expressed in a | |
112 | .I timeval | |
113 | structure (seconds plus microseconds). | |
d1cd1e05 MH |
114 | .TP |
115 | .I ru_stime | |
57440a98 MK |
116 | This is the total amount of time spent executing in kernel mode, |
117 | expressed in a | |
118 | .I timeval | |
119 | structure (seconds plus microseconds). | |
d1cd1e05 | 120 | .TP |
c90ccb4e | 121 | .IR ru_maxrss " (since Linux 2.6.32)" |
e3948c69 MK |
122 | This is the maximum resident set size used (in kilobytes). |
123 | For | |
57440a98 | 124 | .BR RUSAGE_CHILDREN , |
c90ccb4e MH |
125 | this is the resident set size of the largest child, not the maximum |
126 | resident set size of the process tree. | |
d1cd1e05 MH |
127 | .TP |
128 | .IR ru_ixrss " (unmaintained)" | |
14f1e036 MK |
129 | This field is currently unused on Linux. |
130 | .\" On some systems, | |
131 | .\" this is the integral of the text segment memory consumption, | |
132 | .\" expressed in kilobyte-seconds. | |
d1cd1e05 MH |
133 | .TP |
134 | .IR ru_idrss " (unmaintained)" | |
14f1e036 MK |
135 | This field is currently unused on Linux. |
136 | .\" On some systems, this is the integral of the data segment memory consumption, | |
137 | .\" expressed in kilobyte-seconds. | |
d1cd1e05 MH |
138 | .TP |
139 | .IR ru_isrss " (unmaintained)" | |
14f1e036 MK |
140 | This field is currently unused on Linux. |
141 | .\" On some systems, this is the integral of the stack memory consumption, | |
142 | .\" expressed in kilobyte-seconds. | |
d1cd1e05 MH |
143 | .TP |
144 | .I ru_minflt | |
57440a98 | 145 | The number of page faults serviced without any I/O activity; here |
d1cd1e05 MH |
146 | I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from |
147 | the list of pages awaiting reallocation. | |
148 | .TP | |
149 | .I ru_majflt | |
57440a98 | 150 | The number of page faults serviced that required I/O activity. |
d1cd1e05 MH |
151 | .TP |
152 | .IR ru_nswap " (unmaintained)" | |
14f1e036 MK |
153 | This field is currently unused on Linux. |
154 | .\" On some systems, this is the number of swaps out of physical memory. | |
d1cd1e05 MH |
155 | .TP |
156 | .IR ru_inblock " (since Linux 2.6.22)" | |
9ee4a2b6 | 157 | The number of times the filesystem had to perform input. |
d1cd1e05 MH |
158 | .TP |
159 | .IR ru_oublock " (since Linux 2.6.22)" | |
9ee4a2b6 | 160 | The number of times the filesystem had to perform output. |
d1cd1e05 MH |
161 | .TP |
162 | .IR ru_msgsnd " (unmaintained)" | |
14f1e036 | 163 | This field is currently unused on Linux. |
87f8e275 | 164 | .\" On FreeBSD 6.2, this appears to measure messages sent over sockets |
14f1e036 MK |
165 | .\" On some systems, |
166 | .\" this field records the number of messages sent over sockets. | |
d1cd1e05 MH |
167 | .TP |
168 | .IR ru_msgrcv " (unmaintained)" | |
14f1e036 | 169 | This field is currently unused on Linux. |
87f8e275 | 170 | .\" On FreeBSD 6.2, this appears to measure messages received over sockets |
14f1e036 MK |
171 | .\" On some systems, |
172 | .\" this field records the number of messages received over sockets. | |
d1cd1e05 MH |
173 | .TP |
174 | .IR ru_nsignals " (unmaintained)" | |
14f1e036 MK |
175 | This field is currently unused on Linux. |
176 | .\" On some systems, this field records the number of signals received. | |
d1cd1e05 MH |
177 | .TP |
178 | .IR ru_nvcsw " (since Linux 2.6)" | |
57440a98 | 179 | The number of times a context switch resulted due to a process |
d1cd1e05 MH |
180 | voluntarily giving up the processor before its time slice was |
181 | completed (usually to await availability of a resource). | |
182 | .TP | |
183 | .IR ru_nivcsw " (since Linux 2.6)" | |
57440a98 | 184 | The number of times a context switch resulted due to a higher |
d1cd1e05 MH |
185 | priority process becoming runnable or because the current process |
186 | exceeded its time slice. | |
187 | .PP | |
47297adb | 188 | .SH RETURN VALUE |
c13182ef MK |
189 | On success, zero is returned. |
190 | On error, \-1 is returned, and | |
e3a887db MK |
191 | .I errno |
192 | is set appropriately. | |
193 | .SH ERRORS | |
194 | .TP | |
195 | .B EFAULT | |
196 | .I usage | |
197 | points outside the accessible address space. | |
198 | .TP | |
199 | .B EINVAL | |
200 | .I who | |
201 | is invalid. | |
47e94221 ZL |
202 | .SH ATTRIBUTES |
203 | For an explanation of the terms used in this section, see | |
204 | .BR attributes (7). | |
205 | .TS | |
206 | allbox; | |
207 | lb lb lb | |
208 | l l l. | |
209 | Interface Attribute Value | |
210 | T{ | |
211 | .BR getrusage () | |
212 | T} Thread safety MT-Safe | |
213 | .TE | |
efeece04 | 214 | .sp 1 |
47297adb | 215 | .SH CONFORMING TO |
3973434f MK |
216 | POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. |
217 | POSIX.1 specifies | |
97c1eac8 | 218 | .BR getrusage (), |
33a0ccb2 | 219 | but specifies only the fields |
97c1eac8 MK |
220 | .I ru_utime |
221 | and | |
222 | .IR ru_stime . | |
efeece04 | 223 | .PP |
94ce95ef MK |
224 | .B RUSAGE_THREAD |
225 | is Linux-specific. | |
e3a887db | 226 | .SH NOTES |
dfcc37a6 MK |
227 | Resource usage metrics are preserved across an |
228 | .BR execve (2). | |
efeece04 | 229 | .PP |
e3a887db MK |
230 | Including |
231 | .I <sys/time.h> | |
232 | is not required these days, but increases portability. | |
233 | (Indeed, | |
234 | .I struct timeval | |
235 | is defined in | |
236 | .IR <sys/time.h> .) | |
237 | .PP | |
238 | In Linux kernel versions before 2.6.9, if the disposition of | |
239 | .B SIGCHLD | |
240 | is set to | |
241 | .B SIG_IGN | |
242 | then the resource usages of child processes | |
243 | are automatically included in the value returned by | |
244 | .BR RUSAGE_CHILDREN , | |
97c1eac8 | 245 | although POSIX.1-2001 explicitly prohibits this. |
cfea5132 | 246 | This nonconformance is rectified in Linux 2.6.9 and later. |
e3a887db MK |
247 | .\" See the description of getrusage() in XSH. |
248 | .\" A similar statement was also in SUSv2. | |
dd3568a1 | 249 | .PP |
bc5ec131 MK |
250 | The structure definition shown at the start of this page |
251 | was taken from 4.3BSD Reno. | |
efeece04 | 252 | .PP |
8a18a944 MK |
253 | Ancient systems provided a |
254 | .BR vtimes () | |
255 | function with a similar purpose to | |
256 | .BR getrusage (). | |
257 | For backward compatibility, glibc also provides | |
258 | .BR vtimes (). | |
259 | All new applications should be written using | |
260 | .BR getrusage (). | |
efeece04 | 261 | .PP |
94ce95ef | 262 | See also the description of |
750653a8 | 263 | .IR /proc/[pid]/stat |
94ce95ef MK |
264 | in |
265 | .BR proc (5). | |
47297adb | 266 | .SH SEE ALSO |
0eb44391 | 267 | .BR clock_gettime (2), |
e3a887db MK |
268 | .BR getrlimit (2), |
269 | .BR times (2), | |
270 | .BR wait (2), | |
0302f101 | 271 | .BR wait4 (2), |
0eb44391 | 272 | .BR clock (3) |