1.\" Copyright (c) 1985, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)getrusage.2 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt GETRUSAGE 2 10.Os BSD 4 11.Sh NAME 12.Nm getrusage 13.Nd get information about resource utilization 14.Sh SYNOPSIS 15.Fd #include <sys/time.h> 16.Fd #include <sys/resource.h> 17.Fd #define RUSAGE_SELF 0 18.Fd #define RUSAGE_CHILDREN -1 19.Ft int 20.Fn getrusage "int who" "struct rusage *rusage" 21.Sh DESCRIPTION 22.Fn Getrusage 23returns information describing the resources utilized by the current 24process, or all its terminated child processes. 25The 26.Fa who 27parameter is either 28.Dv RUSAGE_SELF 29or 30.Dv RUSAGE_CHILDREN . 31The buffer to which 32.Fa rusage 33points will be filled in with 34the following structure: 35.Bd -literal 36struct rusage { 37 struct timeval ru_utime; /* user time used */ 38 struct timeval ru_stime; /* system time used */ 39 long ru_maxrss; /* integral max resident set size */ 40 long ru_ixrss; /* integral shared text memory size */ 41 long ru_idrss; /* integral unshared data size */ 42 long ru_isrss; /* integral unshared stack size */ 43 long ru_minflt; /* page reclaims */ 44 long ru_majflt; /* page faults */ 45 long ru_nswap; /* swaps */ 46 long ru_inblock; /* block input operations */ 47 long ru_oublock; /* block output operations */ 48 long ru_msgsnd; /* messages sent */ 49 long ru_msgrcv; /* messages received */ 50 long ru_nsignals; /* signals received */ 51 long ru_nvcsw; /* voluntary context switches */ 52 long ru_nivcsw; /* involuntary context switches */ 53}; 54.Ed 55.Pp 56The fields are interpreted as follows: 57.Bl -tag -width ru_minfltaa 58.It Fa ru_utime 59the total amount of time spent executing in user mode. 60.It Fa ru_stime 61the total amount of time spent in the system executing on behalf 62of the process(es). 63.It Fa ru_maxrss 64the maximum resident set size utilized (in kilobytes). 65.It Fa ru_ixrss 66an \*(lqintegral\*(rq value indicating the amount of memory used 67by the text segment 68that was also shared among other processes. This value is expressed 69in units of kilobytes * ticks-of-execution. 70.It Fa ru_idrss 71an integral value of the amount of unshared memory residing in the 72data segment of a process (expressed in units of 73kilobytes * ticks-of-execution). 74.It Fa ru_isrss 75an integral value of the amount of unshared memory residing in the 76stack segment of a process (expressed in units of 77kilobytes * ticks-of-execution). 78.It Fa ru_minflt 79the number of page faults serviced without any I/O activity; here 80I/O activity is avoided by \*(lqreclaiming\*(rq a page frame from 81the list of pages awaiting reallocation. 82.It Fa ru_majflt 83the number of page faults serviced that required I/O activity. 84.It Fa ru_nswap 85the number of times a process was \*(lqswapped\*(rq out of main 86memory. 87.It Fa ru_inblock 88the number of times the file system had to perform input. 89.It Fa ru_oublock 90the number of times the file system had to perform output. 91.It Fa ru_msgsnd 92the number of IPC messages sent. 93.It Fa ru_msgrcv 94the number of IPC messages received. 95.It Fa ru_nsignals 96the number of signals delivered. 97.It Fa ru_nvcsw 98the number of times a context switch resulted due to a process 99voluntarily giving up the processor before its time slice was 100completed (usually to await availability of a resource). 101.It Fa ru_nivcsw 102the number of times a context switch resulted due to a higher 103priority process becoming runnable or because the current process 104exceeded its time slice. 105.El 106.Sh NOTES 107The numbers 108.Fa ru_inblock 109and 110.Fa ru_oublock 111account only for real 112I/O; data supplied by the caching mechanism is charged only 113to the first process to read or write the data. 114.Sh ERRORS 115.Fn Getrusage 116returns -1 on error. 117The possible errors are: 118.Bl -tag -width Er 119.It Bq Er EINVAL 120The 121.Fa who 122parameter is not a valid value. 123.It Bq Er EFAULT 124The address specified by the 125.Fa rusage 126parameter is not in a valid part of the process address space. 127.El 128.Sh SEE ALSO 129.Xr gettimeofday 2 , 130.Xr wait 2 131.Sh BUGS 132There is no way to obtain information about a child process 133that has not yet terminated. 134.Sh HISTORY 135The 136.Nm 137function call appeared in 138.Bx 4.2 . 139