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