]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getrusage.2
getrusage.2: tfix
[thirdparty/man-pages.git] / man2 / getrusage.2
CommitLineData
e3a887db
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992
6883b3e7 4.\" and Copyright (c) 2002 Michael Kerrisk
e3a887db
MK
5.\"
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.
9.\"
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.
c13182ef 14.\"
e3a887db
MK
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
21.\" professionally.
c13182ef 22.\"
e3a887db
MK
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
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.\"
e3f4bf3e 39.TH GETRUSAGE 2 2010-05-24 "Linux" "Linux Programmer's Manual"
e3a887db
MK
40.SH NAME
41getrusage \- 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 ()
94ce95ef
MK
51returns resource usage measures for
52.IR who ,
53which can be one of the following:
54.TP
2914a14d
MK
55.B RUSAGE_SELF
56Return resource usage statistics for the calling process,
94ce95ef
MK
57which is the sum of resources used by all threads in the process.
58.TP
2914a14d 59.B RUSAGE_CHILDREN
94ce95ef
MK
60Return resource usage statistics for all children of the
61calling process that have terminated and been waited for.
62These statistics will include the resources used by grandchildren,
63and further removed descendants,
64if all of the intervening descendants waited on their terminated children.
65.TP
66.BR RUSAGE_THREAD " (since Linux 2.6.26)"
67Return resource usage statistics for the calling thread.
68.PP
69The resource usages are returned in the structure pointed to by
70.IR usage ,
71which has the following form:
c13182ef 72.PP
a08ea57c 73.in +4n
e3a887db
MK
74.nf
75struct rusage {
57440a98
MK
76 struct timeval ru_utime; /* user CPU time used */
77 struct timeval ru_stime; /* system CPU time used */
e3a887db
MK
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 */
57440a98
MK
82 long ru_minflt; /* page reclaims (soft page faults) */
83 long ru_majflt; /* page faults (hard page faults) */
e3a887db
MK
84 long ru_nswap; /* swaps */
85 long ru_inblock; /* block input operations */
86 long ru_oublock; /* block output operations */
57440a98
MK
87 long ru_msgsnd; /* IPC messages sent */
88 long ru_msgrcv; /* IPC messages received */
e3a887db
MK
89 long ru_nsignals; /* signals received */
90 long ru_nvcsw; /* voluntary context switches */
91 long ru_nivcsw; /* involuntary context switches */
92};
93.fi
a08ea57c 94.in
d1cd1e05
MH
95.PP
96Not all fields are completed; unmaintained fields are set to zero by
97the kernel. The fields are interpreted as follows:
98.TP
99.I ru_utime
57440a98
MK
100This is the total amount of time spent executing in user mode,
101expressed in a
102.I timeval
103structure (seconds plus microseconds).
d1cd1e05
MH
104.TP
105.I ru_stime
57440a98
MK
106This is the total amount of time spent executing in kernel mode,
107expressed in a
108.I timeval
109structure (seconds plus microseconds).
d1cd1e05 110.TP
c90ccb4e 111.IR ru_maxrss " (since Linux 2.6.32)"
57440a98
MK
112This is the maximum resident set size used (in kilobytes). For
113.BR RUSAGE_CHILDREN ,
c90ccb4e
MH
114this is the resident set size of the largest child, not the maximum
115resident set size of the process tree.
d1cd1e05
MH
116.TP
117.IR ru_ixrss " (unmaintained)"
57440a98
MK
118On some systems, this is the integral of the text segment memory consumption,
119expressed in kilobyte-seconds.
d1cd1e05
MH
120.TP
121.IR ru_idrss " (unmaintained)"
57440a98
MK
122On some systems, this is the integral of the data segment memory consumption,
123expressed in kilobyte-seconds.
d1cd1e05
MH
124.TP
125.IR ru_isrss " (unmaintained)"
57440a98
MK
126On some systems, this is the integral of the stack memory consumption,
127expressed in kilobyte-seconds.
d1cd1e05
MH
128.TP
129.I ru_minflt
57440a98 130The number of page faults serviced without any I/O activity; here
d1cd1e05
MH
131I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
132the list of pages awaiting reallocation.
133.TP
134.I ru_majflt
57440a98 135The number of page faults serviced that required I/O activity.
d1cd1e05
MH
136.TP
137.IR ru_nswap " (unmaintained)"
57440a98 138On some systems, this is the number of swaps out of physical memory.
d1cd1e05
MH
139.TP
140.IR ru_inblock " (since Linux 2.6.22)"
57440a98 141The number of times the file system had to perform input.
d1cd1e05
MH
142.TP
143.IR ru_oublock " (since Linux 2.6.22)"
57440a98 144The number of times the file system had to perform output.
d1cd1e05
MH
145.TP
146.IR ru_msgsnd " (unmaintained)"
57440a98
MK
147.\" On FreeBSD 6.2, this appears to measure messages sent on sockets
148On some systems,
149this field records the number of messages sent over sockets.
d1cd1e05
MH
150.TP
151.IR ru_msgrcv " (unmaintained)"
57440a98
MK
152.\" On FreeBSD 6.2, this appears to measure messages received on sockets
153On some systems,
154this field records the number of messages received over sockets.
d1cd1e05
MH
155.TP
156.IR ru_nsignals " (unmaintained)"
503a80c7 157On some systems, this field records the number of signals received.
d1cd1e05
MH
158.TP
159.IR ru_nvcsw " (since Linux 2.6)"
57440a98 160The number of times a context switch resulted due to a process
d1cd1e05
MH
161voluntarily giving up the processor before its time slice was
162completed (usually to await availability of a resource).
163.TP
164.IR ru_nivcsw " (since Linux 2.6)"
57440a98 165The number of times a context switch resulted due to a higher
d1cd1e05
MH
166priority process becoming runnable or because the current process
167exceeded its time slice.
168.PP
e3a887db 169.SH "RETURN VALUE"
c13182ef
MK
170On success, zero is returned.
171On error, \-1 is returned, and
e3a887db
MK
172.I errno
173is set appropriately.
174.SH ERRORS
175.TP
176.B EFAULT
177.I usage
178points outside the accessible address space.
179.TP
180.B EINVAL
181.I who
182is invalid.
183.SH "CONFORMING TO"
c13182ef
MK
184SVr4, 4.3BSD.
185POSIX.1-2001 specifies
97c1eac8
MK
186.BR getrusage (),
187but only specifies the fields
188.I ru_utime
189and
190.IR ru_stime .
94ce95ef
MK
191
192.B RUSAGE_THREAD
193is Linux-specific.
e3a887db 194.SH NOTES
dfcc37a6
MK
195Resource usage metrics are preserved across an
196.BR execve (2).
197
e3a887db
MK
198Including
199.I <sys/time.h>
200is not required these days, but increases portability.
201(Indeed,
202.I struct timeval
203is defined in
204.IR <sys/time.h> .)
205.PP
206In Linux kernel versions before 2.6.9, if the disposition of
207.B SIGCHLD
208is set to
209.B SIG_IGN
210then the resource usages of child processes
211are automatically included in the value returned by
212.BR RUSAGE_CHILDREN ,
97c1eac8 213although POSIX.1-2001 explicitly prohibits this.
cfea5132 214This nonconformance is rectified in Linux 2.6.9 and later.
e3a887db
MK
215.\" See the description of getrusage() in XSH.
216.\" A similar statement was also in SUSv2.
217.LP
bc5ec131
MK
218The structure definition shown at the start of this page
219was taken from 4.3BSD Reno.
94ce95ef
MK
220
221See also the description of
222.IR /proc/PID/stat
223in
224.BR proc (5).
e3a887db 225.SH "SEE ALSO"
0eb44391 226.BR clock_gettime (2),
e3a887db
MK
227.BR getrlimit (2),
228.BR times (2),
229.BR wait (2),
0302f101 230.BR wait4 (2),
0eb44391 231.BR clock (3)