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