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