Debian Codegraph @

upstream/debian-trixie/man2/getrusage.2

raw
1 '\" t
2 .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
3 .\" and Copyright (c) 2002 Michael Kerrisk
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .\" 2004-11-16 -- mtk: the getrlimit.2 page, which formerly included
8 .\" coverage of getrusage(2), has been split, so that the latter is
9 .\" now covered in its own getrusage.2. For older details of change
10 .\" history, etc., see getrlimit.2
11 .\"
12 .\" Modified 2004-11-16, mtk, Noted that the nonconformance
13 .\" when SIGCHLD is being ignored is fixed in Linux 2.6.9.
14 .\" 2008-02-22, Sripathi Kodi <[email protected]>: Document RUSAGE_THREAD
15 .\" 2008-05-25, mtk, clarify RUSAGE_CHILDREN + other clean-ups.
16 .\" 2010-05-24, Mark Hills <[email protected]>: Description of fields,
17 .\" document ru_maxrss
18 .\" 2010-05-24, mtk, enhanced description of various fields
19 .\"
20 .TH getrusage 2 2024-05-02 "Linux man-pages 6.9.1"
21 .SH NAME
22 getrusage \- get resource usage
23 .SH LIBRARY
24 Standard C library
25 .RI ( libc ", " \-lc )
26 .SH SYNOPSIS
27 .nf
28 .B #include <sys/resource.h>
29 .P
30 .BI "int getrusage(int " who ", struct rusage *" usage );
31 .fi
32 .SH DESCRIPTION
33 .BR getrusage ()
34 returns resource usage measures for
35 .IR who ,
36 which can be one of the following:
37 .TP
38 .B RUSAGE_SELF
39 Return resource usage statistics for the calling process,
40 which is the sum of resources used by all threads in the process.
41 .TP
42 .B RUSAGE_CHILDREN
43 Return resource usage statistics for all children of the
44 calling process that have terminated and been waited for.
45 These statistics will include the resources used by grandchildren,
46 and further removed descendants,
47 if all of the intervening descendants waited on their terminated children.
48 .TP
49 .BR RUSAGE_THREAD " (since Linux 2.6.26)"
50 Return resource usage statistics for the calling thread.
51 The
52 .B _GNU_SOURCE
53 feature test macro must be defined (before including
54 .I any
55 header file)
56 in order to obtain the definition of this constant from
57 .IR <sys/resource.h> .
58 .P
59 The resource usages are returned in the structure pointed to by
60 .IR usage ,
61 which has the following form:
62 .P
63 .in +4n
64 .EX
65 struct rusage {
66 struct timeval ru_utime; /* user CPU time used */
67 struct timeval ru_stime; /* system CPU time used */
68 long ru_maxrss; /* maximum resident set size */
69 long ru_ixrss; /* integral shared memory size */
70 long ru_idrss; /* integral unshared data size */
71 long ru_isrss; /* integral unshared stack size */
72 long ru_minflt; /* page reclaims (soft page faults) */
73 long ru_majflt; /* page faults (hard page faults) */
74 long ru_nswap; /* swaps */
75 long ru_inblock; /* block input operations */
76 long ru_oublock; /* block output operations */
77 long ru_msgsnd; /* IPC messages sent */
78 long ru_msgrcv; /* IPC messages received */
79 long ru_nsignals; /* signals received */
80 long ru_nvcsw; /* voluntary context switches */
81 long ru_nivcsw; /* involuntary context switches */
82 };
83 .EE
84 .in
85 .P
86 Not all fields are completed;
87 unmaintained fields are set to zero by the kernel.
88 (The unmaintained fields are provided for compatibility with other systems,
89 and because they may one day be supported on Linux.)
90 The fields are interpreted as follows:
91 .TP
92 .I ru_utime
93 This is the total amount of time spent executing in user mode,
94 expressed in a
95 .I timeval
96 structure (seconds plus microseconds).
97 .TP
98 .I ru_stime
99 This is the total amount of time spent executing in kernel mode,
100 expressed in a
101 .I timeval
102 structure (seconds plus microseconds).
103 .TP
104 .IR ru_maxrss " (since Linux 2.6.32)"
105 This is the maximum resident set size used (in kilobytes).
106 For
107 .BR RUSAGE_CHILDREN ,
108 this is the resident set size of the largest child, not the maximum
109 resident set size of the process tree.
110 .TP
111 .IR ru_ixrss " (unmaintained)"
112 This field is currently unused on Linux.
113 .\" On some systems,
114 .\" this is the integral of the text segment memory consumption,
115 .\" expressed in kilobyte-seconds.
116 .TP
117 .IR ru_idrss " (unmaintained)"
118 This field is currently unused on Linux.
119 .\" On some systems, this is the integral of the data segment memory consumption,
120 .\" expressed in kilobyte-seconds.
121 .TP
122 .IR ru_isrss " (unmaintained)"
123 This field is currently unused on Linux.
124 .\" On some systems, this is the integral of the stack memory consumption,
125 .\" expressed in kilobyte-seconds.
126 .TP
127 .I ru_minflt
128 The number of page faults serviced without any I/O activity; here
129 I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
130 the list of pages awaiting reallocation.
131 .TP
132 .I ru_majflt
133 The number of page faults serviced that required I/O activity.
134 .TP
135 .IR ru_nswap " (unmaintained)"
136 This field is currently unused on Linux.
137 .\" On some systems, this is the number of swaps out of physical memory.
138 .TP
139 .IR ru_inblock " (since Linux 2.6.22)"
140 The number of times the filesystem had to perform input.
141 .TP
142 .IR ru_oublock " (since Linux 2.6.22)"
143 The number of times the filesystem had to perform output.
144 .TP
145 .IR ru_msgsnd " (unmaintained)"
146 This field is currently unused on Linux.
147 .\" On FreeBSD 6.2, this appears to measure messages sent over sockets
148 .\" On some systems,
149 .\" this field records the number of messages sent over sockets.
150 .TP
151 .IR ru_msgrcv " (unmaintained)"
152 This field is currently unused on Linux.
153 .\" On FreeBSD 6.2, this appears to measure messages received over sockets
154 .\" On some systems,
155 .\" this field records the number of messages received over sockets.
156 .TP
157 .IR ru_nsignals " (unmaintained)"
158 This field is currently unused on Linux.
159 .\" On some systems, this field records the number of signals received.
160 .TP
161 .IR ru_nvcsw " (since Linux 2.6)"
162 The number of times a context switch resulted due to a process
163 voluntarily giving up the processor before its time slice was
164 completed (usually to await availability of a resource).
165 .TP
166 .IR ru_nivcsw " (since Linux 2.6)"
167 The number of times a context switch resulted due to a higher
168 priority process becoming runnable or because the current process
169 exceeded its time slice.
170 .SH RETURN VALUE
171 On success, zero is returned.
172 On error, \-1 is returned, and
173 .I errno
174 is set to indicate the error.
175 .SH ERRORS
176 .TP
177 .B EFAULT
178 .I usage
179 points outside the accessible address space.
180 .TP
181 .B EINVAL
182 .I who
183 is invalid.
184 .SH ATTRIBUTES
185 For an explanation of the terms used in this section, see
186 .BR attributes (7).
187 .TS
188 allbox;
189 lbx lb lb
190 l l l.
191 Interface Attribute Value
192 T{
193 .na
194 .nh
195 .BR getrusage ()
196 T} Thread safety MT-Safe
197 .TE
198 .SH STANDARDS
199 POSIX.1-2008.
200 .P
201 POSIX.1 specifies
202 .BR getrusage (),
203 but specifies only the fields
204 .I ru_utime
205 and
206 .IR ru_stime .
207 .P
208 .B RUSAGE_THREAD
209 is Linux-specific.
210 .SH HISTORY
211 POSIX.1-2001, SVr4, 4.3BSD.
212 .P
213 Before Linux 2.6.9, if the disposition of
214 .B SIGCHLD
215 is set to
216 .B SIG_IGN
217 then the resource usages of child processes
218 are automatically included in the value returned by
219 .BR RUSAGE_CHILDREN ,
220 although POSIX.1-2001 explicitly prohibits this.
221 This nonconformance is rectified in Linux 2.6.9 and later.
222 .\" See the description of getrusage() in XSH.
223 .\" A similar statement was also in SUSv2.
224 .P
225 The structure definition shown at the start of this page
226 was taken from 4.3BSD Reno.
227 .P
228 Ancient systems provided a
229 .BR vtimes ()
230 function with a similar purpose to
231 .BR getrusage ().
232 For backward compatibility, glibc (up until Linux 2.32) also provides
233 .BR vtimes ().
234 All new applications should be written using
235 .BR getrusage ().
236 (Since Linux 2.33, glibc no longer provides an
237 .BR vtimes ()
238 implementation.)
239 .SH NOTES
240 Resource usage metrics are preserved across an
241 .BR execve (2).
242 .SH SEE ALSO
243 .BR clock_gettime (2),
244 .BR getrlimit (2),
245 .BR times (2),
246 .BR wait (2),
247 .BR wait4 (2),
248 .BR clock (3),
249 .BR proc_pid_stat (5),
250 .BR proc_pid_io (5)