]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getrusage.2
sync
[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.
14.\"
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.
22.\"
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
25.\"
704a18f0
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.\"
c10859eb 34.TH GETRUSAGE 2 2004-11-16 "Linux 2.6.9" "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
47of either
48.B RUSAGE_SELF
49or
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.
54.PP
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"
78On success, zero is returned. On error, \-1 is returned, and
79.I errno
80is set appropriately.
81.SH ERRORS
82.TP
83.B EFAULT
84.I usage
85points outside the accessible address space.
86.TP
87.B EINVAL
88.I who
89is invalid.
90.SH "CONFORMING TO"
97c1eac8
MK
91SVr4, 4.3BSD.
92POSIX.1-2001 specifies
93.BR getrusage (),
94but only specifies the fields
95.I ru_utime
96and
97.IR ru_stime .
e3a887db
MK
98.SH NOTES
99Including
100.I <sys/time.h>
101is not required these days, but increases portability.
102(Indeed,
103.I struct timeval
104is defined in
105.IR <sys/time.h> .)
106.PP
107In Linux kernel versions before 2.6.9, if the disposition of
108.B SIGCHLD
109is set to
110.B SIG_IGN
111then the resource usages of child processes
112are automatically included in the value returned by
113.BR RUSAGE_CHILDREN ,
97c1eac8 114although POSIX.1-2001 explicitly prohibits this.
e3a887db
MK
115This non-conformance is rectified in Linux 2.6.9 and later.
116.\" See the description of getrusage() in XSH.
117.\" A similar statement was also in SUSv2.
118.LP
b14d4aa5 119The above struct was taken from 4.3BSD Reno.
e3a887db 120Not all fields are meaningful under Linux.
dd61d68c
MK
121In linux 2.4 only the fields
122.IR ru_utime ,
123.IR ru_stime ,
124.IR ru_minflt ,
e3a887db 125and
dd61d68c 126.IR ru_majflt
e3a887db 127are maintained.
dd61d68c
MK
128Since Linux 2.6,
129.I ru_nvcsw
130and
131.I ru_nivcsw
132are also maintained.
e3a887db
MK
133.SH "SEE ALSO"
134.BR getrlimit (2),
135.BR times (2),
136.BR wait (2),
137.BR wait4 (2)