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