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