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