xref: /dragonfly/lib/libc/sys/getrusage.2 (revision 37de577a)
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.\"     @(#)getrusage.2	8.1 (Berkeley) 6/4/93
29.\" $FreeBSD: src/lib/libc/sys/getrusage.2,v 1.10.2.5 2001/12/14 18:34:00 ru Exp $
30.\"
31.Dd June 4, 1993
32.Dt GETRUSAGE 2
33.Os
34.Sh NAME
35.Nm getrusage
36.Nd get information about resource utilization
37.Sh LIBRARY
38.Lb libc
39.Sh SYNOPSIS
40.In sys/types.h
41.In sys/time.h
42.In sys/resource.h
43.Fd "#define   RUSAGE_SELF       0"
44.Fd "#define   RUSAGE_CHILDREN  -1"
45.Ft int
46.Fn getrusage "int who" "struct rusage *rusage"
47.Sh DESCRIPTION
48.Fn Getrusage
49returns information describing the resources utilized by the current
50process, or all its terminated child processes.
51The
52.Fa who
53parameter is either
54.Dv RUSAGE_SELF
55or
56.Dv RUSAGE_CHILDREN .
57The buffer to which
58.Fa rusage
59points will be filled in with
60the following structure:
61.Bd -literal
62struct rusage {
63        struct timeval ru_utime; /* user time used */
64        struct timeval ru_stime; /* system time used */
65        long ru_maxrss;          /* max resident set size */
66        long ru_ixrss;           /* integral shared text memory size */
67        long ru_idrss;           /* integral unshared data size */
68        long ru_isrss;           /* integral unshared stack size */
69        long ru_minflt;          /* page reclaims */
70        long ru_majflt;          /* page faults */
71        long ru_nswap;           /* swaps */
72        long ru_inblock;         /* block input operations */
73        long ru_oublock;         /* block output operations */
74        long ru_msgsnd;          /* messages sent */
75        long ru_msgrcv;          /* messages received */
76        long ru_nsignals;        /* signals received */
77        long ru_nvcsw;           /* voluntary context switches */
78        long ru_nivcsw;          /* involuntary context switches */
79};
80.Ed
81.Pp
82The fields are interpreted as follows:
83.Bl -tag -width ru_minfltaa
84.It Fa ru_utime
85the total amount of time spent executing in user mode.
86.It Fa ru_stime
87the total amount of time spent in the system executing on behalf
88of the process(es).
89.It Fa ru_maxrss
90the maximum resident set size utilized (in kilobytes).
91.It Fa ru_ixrss
92an
93.Dq integral
94value indicating the amount of memory used
95by the text segment
96that was also shared among other processes.  This value is expressed
97in units of kilobytes * ticks-of-execution.
98Ticks are statistics clock ticks.
99The statistics clock has a frequency of
100.Fn sysconf _SC_CLOCK_TCK
101ticks per second.
102.It Fa ru_idrss
103an integral value of the amount of unshared memory residing in the
104data segment of a process (expressed in units of
105kilobytes * ticks-of-execution).
106.It Fa ru_isrss
107an integral value of the amount of unshared memory residing in the
108stack segment of a process (expressed in units of
109kilobytes * ticks-of-execution).
110.It Fa ru_minflt
111the number of page faults serviced without any I/O activity; here
112I/O activity is avoided by
113.Dq reclaiming
114a page frame from
115the list of pages awaiting reallocation.
116.It Fa ru_majflt
117the number of page faults serviced that required I/O activity.
118.It Fa ru_nswap
119the number of times a process was
120.Dq swapped
121out of main
122memory.
123.It Fa ru_inblock
124the number of times the file system had to perform input.
125.It Fa ru_oublock
126the number of times the file system had to perform output.
127.It Fa ru_msgsnd
128the number of IPC messages sent.
129.It Fa ru_msgrcv
130the number of IPC messages received.
131.It Fa ru_nsignals
132the number of signals delivered.
133.It Fa ru_nvcsw
134the number of times a context switch resulted due to a process
135voluntarily giving up the processor before its time slice was
136completed (usually to await availability of a resource).
137.It Fa ru_nivcsw
138the number of times a context switch resulted due to a higher
139priority process becoming runnable or because the current process
140exceeded its time slice.
141.El
142.Sh NOTES
143The numbers
144.Fa ru_inblock
145and
146.Fa ru_oublock
147account only for real
148I/O; data supplied by the caching mechanism is charged only
149to the first process to read or write the data.
150.Sh RETURN VALUES
151.Rv -std getrusage
152.Sh ERRORS
153The
154.Fn getrusage
155function will fail if:
156.Bl -tag -width Er
157.It Bq Er EINVAL
158The
159.Fa who
160parameter is not a valid value.
161.It Bq Er EFAULT
162The address specified by the
163.Fa rusage
164parameter is not in a valid part of the process address space.
165.El
166.Sh SEE ALSO
167.Xr gettimeofday 2 ,
168.Xr wait 2 ,
169.Xr clocks 7
170.Sh HISTORY
171The
172.Fn getrusage
173function call appeared in
174.Bx 4.2 .
175.Sh BUGS
176There is no way to obtain information about a child process
177that has not yet terminated.
178