]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getrusage.2
msgop.2, semop.2, lgamma.3, tgamma.3, mdoc.samples.7: Global fix: s/non-positive...
[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
MK
30.\"
31.\" Modified 2004-11-16, mtk, Noted that the non-conformance
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
e3a887db 92.SH "RETURN VALUE"
c13182ef
MK
93On success, zero is returned.
94On error, \-1 is returned, and
e3a887db
MK
95.I errno
96is set appropriately.
97.SH ERRORS
98.TP
99.B EFAULT
100.I usage
101points outside the accessible address space.
102.TP
103.B EINVAL
104.I who
105is invalid.
106.SH "CONFORMING TO"
c13182ef
MK
107SVr4, 4.3BSD.
108POSIX.1-2001 specifies
97c1eac8
MK
109.BR getrusage (),
110but only specifies the fields
111.I ru_utime
112and
113.IR ru_stime .
94ce95ef
MK
114
115.B RUSAGE_THREAD
116is Linux-specific.
e3a887db 117.SH NOTES
dfcc37a6
MK
118Resource usage metrics are preserved across an
119.BR execve (2).
120
e3a887db
MK
121Including
122.I <sys/time.h>
123is not required these days, but increases portability.
124(Indeed,
125.I struct timeval
126is defined in
127.IR <sys/time.h> .)
128.PP
129In Linux kernel versions before 2.6.9, if the disposition of
130.B SIGCHLD
131is set to
132.B SIG_IGN
133then the resource usages of child processes
134are automatically included in the value returned by
135.BR RUSAGE_CHILDREN ,
97c1eac8 136although POSIX.1-2001 explicitly prohibits this.
e3a887db
MK
137This non-conformance is rectified in Linux 2.6.9 and later.
138.\" See the description of getrusage() in XSH.
139.\" A similar statement was also in SUSv2.
140.LP
bc5ec131
MK
141The structure definition shown at the start of this page
142was taken from 4.3BSD Reno.
e3a887db 143Not all fields are meaningful under Linux.
bc5ec131 144In Linux 2.4 only the fields
dd61d68c
MK
145.IR ru_utime ,
146.IR ru_stime ,
147.IR ru_minflt ,
e3a887db 148and
0daa9e92 149.I ru_majflt
e3a887db 150are maintained.
c13182ef 151Since Linux 2.6,
dd61d68c
MK
152.I ru_nvcsw
153and
154.I ru_nivcsw
155are also maintained.
6f6a9bc7
MK
156Since Linux 2.6.22,
157.I ru_inblock
158and
159.I ru_oublock
160are also maintained.
94ce95ef
MK
161
162See also the description of
163.IR /proc/PID/stat
164in
165.BR proc (5).
e3a887db 166.SH "SEE ALSO"
0eb44391 167.BR clock_gettime (2),
e3a887db
MK
168.BR getrlimit (2),
169.BR times (2),
170.BR wait (2),
0302f101 171.BR wait4 (2),
0eb44391 172.BR clock (3)