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