OSDN Git Service

(split) LDP: Update original to LDP v3.65
[linuxjm/LDP_man-pages.git] / original / man2 / getrusage.2
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 2010-09-26 "Linux" "Linux Programmer's Manual"
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>
46 .sp
47 .BI "int getrusage(int " who ", struct rusage *" usage );
48 .SH DESCRIPTION
49 .PP
50 .BR getrusage ()
51 returns resource usage measures for
52 .IR who ,
53 which can be one of the following:
54 .TP
55 .B RUSAGE_SELF
56 Return resource usage statistics for the calling process,
57 which is the sum of resources used by all threads in the process.
58 .TP
59 .B RUSAGE_CHILDREN
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.
68 .PP
69 The resource usages are returned in the structure pointed to by
70 .IR usage ,
71 which has the following form:
72 .PP
73 .in +4n
74 .nf
75 struct rusage {
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 */
92 };
93 .fi
94 .in
95 .PP
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:
101 .TP
102 .I ru_utime
103 This is the total amount of time spent executing in user mode,
104 expressed in a
105 .I timeval
106 structure (seconds plus microseconds).
107 .TP
108 .I ru_stime
109 This is the total amount of time spent executing in kernel mode,
110 expressed in a
111 .I timeval
112 structure (seconds plus microseconds).
113 .TP
114 .IR ru_maxrss " (since Linux 2.6.32)"
115 This is the maximum resident set size used (in kilobytes).
116 For
117 .BR RUSAGE_CHILDREN ,
118 this is the resident set size of the largest child, not the maximum
119 resident set size of the process tree.
120 .TP
121 .IR ru_ixrss " (unmaintained)"
122 This field is currently unused on Linux.
123 .\" On some systems,
124 .\" this is the integral of the text segment memory consumption,
125 .\" expressed in kilobyte-seconds.
126 .TP
127 .IR ru_idrss " (unmaintained)"
128 This field is currently unused on Linux.
129 .\" On some systems, this is the integral of the data segment memory consumption,
130 .\" expressed in kilobyte-seconds.
131 .TP
132 .IR ru_isrss " (unmaintained)"
133 This field is currently unused on Linux.
134 .\" On some systems, this is the integral of the stack memory consumption,
135 .\" expressed in kilobyte-seconds.
136 .TP
137 .I ru_minflt
138 The number of page faults serviced without any I/O activity; here
139 I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
140 the list of pages awaiting reallocation.
141 .TP
142 .I ru_majflt
143 The number of page faults serviced that required I/O activity.
144 .TP
145 .IR ru_nswap  " (unmaintained)"
146 This field is currently unused on Linux.
147 .\" On some systems, this is the number of swaps out of physical memory.
148 .TP
149 .IR ru_inblock " (since Linux 2.6.22)"
150 The number of times the filesystem had to perform input.
151 .TP
152 .IR ru_oublock " (since Linux 2.6.22)"
153 The number of times the filesystem had to perform output.
154 .TP
155 .IR ru_msgsnd " (unmaintained)"
156 This field is currently unused on Linux.
157 .\" On FreeBSD 6.2, this appears to measure messages sent over sockets
158 .\" On some systems,
159 .\" this field records the number of messages sent over sockets.
160 .TP
161 .IR ru_msgrcv " (unmaintained)"
162 This field is currently unused on Linux.
163 .\" On FreeBSD 6.2, this appears to measure messages received over sockets
164 .\" On some systems,
165 .\" this field records the number of messages received over sockets.
166 .TP
167 .IR ru_nsignals " (unmaintained)"
168 This field is currently unused on Linux.
169 .\" On some systems, this field records the number of signals received.
170 .TP
171 .IR ru_nvcsw " (since Linux 2.6)"
172 The number of times a context switch resulted due to a process
173 voluntarily giving up the processor before its time slice was
174 completed (usually to await availability of a resource).
175 .TP
176 .IR ru_nivcsw " (since Linux 2.6)"
177 The number of times a context switch resulted due to a higher
178 priority process becoming runnable or because the current process
179 exceeded its time slice.
180 .PP
181 .SH RETURN VALUE
182 On success, zero is returned.
183 On error, \-1 is returned, and
184 .I errno
185 is set appropriately.
186 .SH ERRORS
187 .TP
188 .B EFAULT
189 .I usage
190 points outside the accessible address space.
191 .TP
192 .B EINVAL
193 .I who
194 is invalid.
195 .SH CONFORMING TO
196 SVr4, 4.3BSD.
197 POSIX.1-2001 specifies
198 .BR getrusage (),
199 but specifies only the fields
200 .I ru_utime
201 and
202 .IR ru_stime .
203
204 .B RUSAGE_THREAD
205 is Linux-specific.
206 .SH NOTES
207 Resource usage metrics are preserved across an
208 .BR execve (2).
209
210 Including
211 .I <sys/time.h>
212 is not required these days, but increases portability.
213 (Indeed,
214 .I struct timeval
215 is defined in
216 .IR <sys/time.h> .)
217 .PP
218 In Linux kernel versions before 2.6.9, if the disposition of
219 .B SIGCHLD
220 is set to
221 .B SIG_IGN
222 then the resource usages of child processes
223 are automatically included in the value returned by
224 .BR RUSAGE_CHILDREN ,
225 although POSIX.1-2001 explicitly prohibits this.
226 This nonconformance is rectified in Linux 2.6.9 and later.
227 .\" See the description of getrusage() in XSH.
228 .\" A similar statement was also in SUSv2.
229 .LP
230 The structure definition shown at the start of this page
231 was taken from 4.3BSD Reno.
232
233 Ancient systems provided a
234 .BR vtimes ()
235 function with a similar purpose to
236 .BR getrusage ().
237 For backward compatibility, glibc also provides
238 .BR vtimes ().
239 All new applications should be written using
240 .BR getrusage ().
241
242 See also the description of
243 .IR /proc/PID/stat
244 in
245 .BR proc (5).
246 .SH SEE ALSO
247 .BR clock_gettime (2),
248 .BR getrlimit (2),
249 .BR times (2),
250 .BR wait (2),
251 .BR wait4 (2),
252 .BR clock (3)
253 .SH COLOPHON
254 This page is part of release 3.65 of the Linux
255 .I man-pages
256 project.
257 A description of the project,
258 and information about reporting bugs,
259 can be found at
260 \%http://www.kernel.org/doc/man\-pages/.