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