]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getrusage.2
getrusage.2: Description of maintained fields
[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.
e3a887db 35.\"
6f6a9bc7 36.TH GETRUSAGE 2 2009-08-25 "Linux" "Linux Programmer's Manual"
e3a887db
MK
37.SH NAME
38getrusage \- get resource usage
39.SH SYNOPSIS
40.B #include <sys/time.h>
41.br
42.B #include <sys/resource.h>
43.sp
44.BI "int getrusage(int " who ", struct rusage *" usage );
45.SH DESCRIPTION
46.PP
47.BR getrusage ()
94ce95ef
MK
48returns resource usage measures for
49.IR who ,
50which can be one of the following:
51.TP
2914a14d
MK
52.B RUSAGE_SELF
53Return resource usage statistics for the calling process,
94ce95ef
MK
54which is the sum of resources used by all threads in the process.
55.TP
2914a14d 56.B RUSAGE_CHILDREN
94ce95ef
MK
57Return resource usage statistics for all children of the
58calling process that have terminated and been waited for.
59These statistics will include the resources used by grandchildren,
60and further removed descendants,
61if all of the intervening descendants waited on their terminated children.
62.TP
63.BR RUSAGE_THREAD " (since Linux 2.6.26)"
64Return resource usage statistics for the calling thread.
65.PP
66The resource usages are returned in the structure pointed to by
67.IR usage ,
68which has the following form:
c13182ef 69.PP
a08ea57c 70.in +4n
e3a887db
MK
71.nf
72struct rusage {
73 struct timeval ru_utime; /* user time used */
74 struct timeval ru_stime; /* system time used */
75 long ru_maxrss; /* maximum resident set size */
76 long ru_ixrss; /* integral shared memory size */
77 long ru_idrss; /* integral unshared data size */
78 long ru_isrss; /* integral unshared stack size */
79 long ru_minflt; /* page reclaims */
80 long ru_majflt; /* page faults */
81 long ru_nswap; /* swaps */
82 long ru_inblock; /* block input operations */
83 long ru_oublock; /* block output operations */
84 long ru_msgsnd; /* messages sent */
85 long ru_msgrcv; /* messages received */
86 long ru_nsignals; /* signals received */
87 long ru_nvcsw; /* voluntary context switches */
88 long ru_nivcsw; /* involuntary context switches */
89};
90.fi
a08ea57c 91.in
d1cd1e05
MH
92.PP
93Not all fields are completed; unmaintained fields are set to zero by
94the kernel. The fields are interpreted as follows:
95.TP
96.I ru_utime
97the total amount of time spent executing in user mode.
98.TP
99.I ru_stime
100the total amount of time spent in the system executing on behalf
101of the process(es).
102.TP
103.IR ru_maxrss " (unmaintained)"
104.TP
105.IR ru_ixrss " (unmaintained)"
106.TP
107.IR ru_idrss " (unmaintained)"
108.TP
109.IR ru_isrss " (unmaintained)"
110.TP
111.I ru_minflt
112the number of page faults serviced without any I/O activity; here
113I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
114the list of pages awaiting reallocation.
115.TP
116.I ru_majflt
117the number of page faults serviced that required I/O activity.
118.TP
119.IR ru_nswap " (unmaintained)"
120.TP
121.IR ru_inblock " (since Linux 2.6.22)"
122the number of times the file system had to perform input.
123.TP
124.IR ru_oublock " (since Linux 2.6.22)"
125the number of times the file system had to perform output.
126.TP
127.IR ru_msgsnd " (unmaintained)"
128.TP
129.IR ru_msgrcv " (unmaintained)"
130.TP
131.IR ru_nsignals " (unmaintained)"
132.TP
133.IR ru_nvcsw " (since Linux 2.6)"
134the number of times a context switch resulted due to a process
135voluntarily giving up the processor before its time slice was
136completed (usually to await availability of a resource).
137.TP
138.IR ru_nivcsw " (since Linux 2.6)"
139the number of times a context switch resulted due to a higher
140priority process becoming runnable or because the current process
141exceeded its time slice.
142.PP
e3a887db 143.SH "RETURN VALUE"
c13182ef
MK
144On success, zero is returned.
145On error, \-1 is returned, and
e3a887db
MK
146.I errno
147is set appropriately.
148.SH ERRORS
149.TP
150.B EFAULT
151.I usage
152points outside the accessible address space.
153.TP
154.B EINVAL
155.I who
156is invalid.
157.SH "CONFORMING TO"
c13182ef
MK
158SVr4, 4.3BSD.
159POSIX.1-2001 specifies
97c1eac8
MK
160.BR getrusage (),
161but only specifies the fields
162.I ru_utime
163and
164.IR ru_stime .
94ce95ef
MK
165
166.B RUSAGE_THREAD
167is Linux-specific.
e3a887db 168.SH NOTES
dfcc37a6
MK
169Resource usage metrics are preserved across an
170.BR execve (2).
171
e3a887db
MK
172Including
173.I <sys/time.h>
174is not required these days, but increases portability.
175(Indeed,
176.I struct timeval
177is defined in
178.IR <sys/time.h> .)
179.PP
180In Linux kernel versions before 2.6.9, if the disposition of
181.B SIGCHLD
182is set to
183.B SIG_IGN
184then the resource usages of child processes
185are automatically included in the value returned by
186.BR RUSAGE_CHILDREN ,
97c1eac8 187although POSIX.1-2001 explicitly prohibits this.
cfea5132 188This nonconformance is rectified in Linux 2.6.9 and later.
e3a887db
MK
189.\" See the description of getrusage() in XSH.
190.\" A similar statement was also in SUSv2.
191.LP
bc5ec131
MK
192The structure definition shown at the start of this page
193was taken from 4.3BSD Reno.
94ce95ef
MK
194
195See also the description of
196.IR /proc/PID/stat
197in
198.BR proc (5).
e3a887db 199.SH "SEE ALSO"
0eb44391 200.BR clock_gettime (2),
e3a887db
MK
201.BR getrlimit (2),
202.BR times (2),
203.BR wait (2),
0302f101 204.BR wait4 (2),
0eb44391 205.BR clock (3)