xref: /netbsd/lib/libc/sys/getrusage.2 (revision c4a72b64)
1.\"	$NetBSD: getrusage.2,v 1.13 2002/10/01 18:10:44 wiz Exp $
2.\"
3.\" Copyright (c) 1985, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)getrusage.2	8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt GETRUSAGE 2
38.Os
39.Sh NAME
40.Nm getrusage
41.Nd get information about resource utilization
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.Fd #include \*[Lt]sys/resource.h\*[Gt]
46.Fd #define	RUSAGE_SELF	 0
47.Fd #define	RUSAGE_CHILDREN	-1
48.Ft int
49.Fn getrusage "int who" "struct rusage *rusage"
50.Sh DESCRIPTION
51.Fn getrusage
52returns information describing the resources utilized by the current
53process, or all its terminated child processes.
54The
55.Fa who
56parameter is either
57.Dv RUSAGE_SELF
58or
59.Dv RUSAGE_CHILDREN .
60The buffer to which
61.Fa rusage
62points will be filled in with
63the following structure:
64.Bd -literal
65struct rusage {
66        struct timeval ru_utime; /* user time used */
67        struct timeval ru_stime; /* system time used */
68        long ru_maxrss;          /* max resident set size */
69        long ru_ixrss;           /* integral shared text memory size */
70        long ru_idrss;           /* integral unshared data size */
71        long ru_isrss;           /* integral unshared stack size */
72        long ru_minflt;          /* page reclaims */
73        long ru_majflt;          /* page faults */
74        long ru_nswap;           /* swaps */
75        long ru_inblock;         /* block input operations */
76        long ru_oublock;         /* block output operations */
77        long ru_msgsnd;          /* messages sent */
78        long ru_msgrcv;          /* messages received */
79        long ru_nsignals;        /* signals received */
80        long ru_nvcsw;           /* voluntary context switches */
81        long ru_nivcsw;          /* involuntary context switches */
82};
83.Ed
84.Pp
85The fields are interpreted as follows:
86.Bl -tag -width ru_minfltaa
87.It Fa ru_utime
88the total amount of time spent executing in user mode.
89.It Fa ru_stime
90the total amount of time spent in the system executing on behalf
91of the process(es).
92.It Fa ru_maxrss
93the maximum resident set size utilized (in kilobytes).
94.It Fa ru_ixrss
95an \*(lqintegral\*(rq value indicating the amount of memory used
96by the text segment
97that was also shared among other processes.
98This value is expressed
99in units of kilobytes * ticks-of-execution.
100.It Fa ru_idrss
101an integral value of the amount of unshared memory residing in the
102data segment of a process (expressed in units of
103kilobytes * ticks-of-execution).
104.It Fa ru_isrss
105an integral value of the amount of unshared memory residing in the
106stack segment of a process (expressed in units of
107kilobytes * ticks-of-execution).
108.It Fa ru_minflt
109the number of page faults serviced without any I/O activity; here
110I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
111the list of pages awaiting reallocation.
112.It Fa ru_majflt
113the number of page faults serviced that required I/O activity.
114.It Fa ru_nswap
115the number of times a process was \*(lqswapped\*(rq out of main
116memory.
117.It Fa ru_inblock
118the number of times the file system had to perform input.
119.It Fa ru_oublock
120the number of times the file system had to perform output.
121.It Fa ru_msgsnd
122the number of IPC messages sent.
123.It Fa ru_msgrcv
124the number of IPC messages received.
125.It Fa ru_nsignals
126the number of signals delivered.
127.It Fa ru_nvcsw
128the number of times a context switch resulted due to a process
129voluntarily giving up the processor before its time slice was
130completed (usually to await availability of a resource).
131.It Fa ru_nivcsw
132the number of times a context switch resulted due to a higher
133priority process becoming runnable or because the current process
134exceeded its time slice.
135.El
136.Sh NOTES
137The numbers
138.Fa ru_inblock
139and
140.Fa ru_oublock
141account only for real
142I/O; data supplied by the caching mechanism is charged only
143to the first process to read or write the data.
144.Sh ERRORS
145.Fn getrusage
146returns -1 on error.
147The possible errors are:
148.Bl -tag -width Er
149.It Bq Er EINVAL
150The
151.Fa who
152parameter is not a valid value.
153.It Bq Er EFAULT
154The address specified by the
155.Fa rusage
156parameter is not in a valid part of the process address space.
157.El
158.Sh SEE ALSO
159.Xr gettimeofday 2 ,
160.Xr wait 2
161.Sh HISTORY
162The
163.Fn getrusage
164function call appeared in
165.Bx 4.2 .
166.Sh BUGS
167There is no way to obtain information about a child process
168that has not yet terminated.
169