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