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