]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getrusage.2
Minor heading changes and reformattings.
[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
e3a887db
MK
29.\" history, etc, see getrlimit.2
30.\"
31.\" Modified 2004-11-16, mtk, Noted that the non-conformance
32.\" when SIGCHLD is being ignored is fixed in 2.6.9.
33.\"
d9343c5c 34.TH GETRUSAGE 2 2004-11-16 "Linux" "Linux Programmer's Manual"
e3a887db
MK
35.SH NAME
36getrusage \- get resource usage
37.SH SYNOPSIS
38.B #include <sys/time.h>
39.br
40.B #include <sys/resource.h>
41.sp
42.BI "int getrusage(int " who ", struct rusage *" usage );
43.SH DESCRIPTION
44.PP
45.BR getrusage ()
46returns current resource usages, for a \fIwho\fP
c13182ef 47of either
e3a887db 48.B RUSAGE_SELF
c13182ef 49or
e3a887db
MK
50.BR RUSAGE_CHILDREN .
51The former asks for resources used by the current process,
52the latter for resources used by those of its children
53that have terminated and have been waited for.
c13182ef 54.PP
e3a887db
MK
55.in +0.5i
56.nf
57struct rusage {
58 struct timeval ru_utime; /* user time used */
59 struct timeval ru_stime; /* system time used */
60 long ru_maxrss; /* maximum resident set size */
61 long ru_ixrss; /* integral shared memory size */
62 long ru_idrss; /* integral unshared data size */
63 long ru_isrss; /* integral unshared stack size */
64 long ru_minflt; /* page reclaims */
65 long ru_majflt; /* page faults */
66 long ru_nswap; /* swaps */
67 long ru_inblock; /* block input operations */
68 long ru_oublock; /* block output operations */
69 long ru_msgsnd; /* messages sent */
70 long ru_msgrcv; /* messages received */
71 long ru_nsignals; /* signals received */
72 long ru_nvcsw; /* voluntary context switches */
73 long ru_nivcsw; /* involuntary context switches */
74};
75.fi
76.in -0.5i
77.SH "RETURN VALUE"
c13182ef
MK
78On success, zero is returned.
79On error, \-1 is returned, and
e3a887db
MK
80.I errno
81is set appropriately.
82.SH ERRORS
83.TP
84.B EFAULT
85.I usage
86points outside the accessible address space.
87.TP
88.B EINVAL
89.I who
90is invalid.
91.SH "CONFORMING TO"
c13182ef
MK
92SVr4, 4.3BSD.
93POSIX.1-2001 specifies
97c1eac8
MK
94.BR getrusage (),
95but only specifies the fields
96.I ru_utime
97and
98.IR ru_stime .
e3a887db
MK
99.SH NOTES
100Including
101.I <sys/time.h>
102is not required these days, but increases portability.
103(Indeed,
104.I struct timeval
105is defined in
106.IR <sys/time.h> .)
107.PP
108In Linux kernel versions before 2.6.9, if the disposition of
109.B SIGCHLD
110is set to
111.B SIG_IGN
112then the resource usages of child processes
113are automatically included in the value returned by
114.BR RUSAGE_CHILDREN ,
97c1eac8 115although POSIX.1-2001 explicitly prohibits this.
e3a887db
MK
116This non-conformance is rectified in Linux 2.6.9 and later.
117.\" See the description of getrusage() in XSH.
118.\" A similar statement was also in SUSv2.
119.LP
b14d4aa5 120The above struct was taken from 4.3BSD Reno.
e3a887db 121Not all fields are meaningful under Linux.
dd61d68c
MK
122In linux 2.4 only the fields
123.IR ru_utime ,
124.IR ru_stime ,
125.IR ru_minflt ,
e3a887db 126and
0daa9e92 127.I ru_majflt
e3a887db 128are maintained.
c13182ef 129Since Linux 2.6,
dd61d68c
MK
130.I ru_nvcsw
131and
132.I ru_nivcsw
133are also maintained.
e3a887db
MK
134.SH "SEE ALSO"
135.BR getrlimit (2),
136.BR times (2),
137.BR wait (2),
138.BR wait4 (2)