xref: /csrg-svn/lib/libc/sys/getrusage.2 (revision 61181)
1*61181Sbostic.\" Copyright (c) 1985, 1991, 1993
2*61181Sbostic.\"	The Regents of the University of California.  All rights reserved.
320144Smckusick.\"
443568Strent.\" %sccs.include.redist.man%
520144Smckusick.\"
6*61181Sbostic.\"     @(#)getrusage.2	8.1 (Berkeley) 06/04/93
737125Sbostic.\"
847208Scael.Dd
947208Scael.Dt GETRUSAGE 2
1047208Scael.Os BSD 4
1147208Scael.Sh NAME
1247208Scael.Nm getrusage
1347208Scael.Nd get information about resource utilization
1447208Scael.Sh SYNOPSIS
1547208Scael.Fd #include <sys/time.h>
1647208Scael.Fd #include <sys/resource.h>
1747208Scael.Fd #define	RUSAGE_SELF	 0
1847208Scael.Fd #define	RUSAGE_CHILDREN	-1
1947208Scael.Ft int
2047208Scael.Fn getrusage "int who" "struct rusage *rusage"
2147208Scael.Sh DESCRIPTION
2247208Scael.Fn Getrusage
2320145Smckusickreturns information describing the resources utilized by the current
2420145Smckusickprocess, or all its terminated child processes.
2520145SmckusickThe
2647208Scael.Fa who
2747208Scaelparameter is either
2847208Scael.Dv RUSAGE_SELF
2947208Scaelor
3047208Scael.Dv RUSAGE_CHILDREN .
3128085SkarelsThe buffer to which
3247208Scael.Fa rusage
3328085Skarelspoints will be filled in with
3420145Smckusickthe following structure:
3547208Scael.Bd -literal
3637125Sbosticstruct rusage {
3747208Scael        struct timeval ru_utime; /* user time used */
3847208Scael        struct timeval ru_stime; /* system time used */
3947208Scael        long ru_maxrss;          /* integral max resident set size */
4047208Scael        long ru_ixrss;           /* integral shared text memory size */
4147208Scael        long ru_idrss;           /* integral unshared data size */
4247208Scael        long ru_isrss;           /* integral unshared stack size */
4347208Scael        long ru_minflt;          /* page reclaims */
4447208Scael        long ru_majflt;          /* page faults */
4547208Scael        long ru_nswap;           /* swaps */
4647208Scael        long ru_inblock;         /* block input operations */
4747208Scael        long ru_oublock;         /* block output operations */
4847208Scael        long ru_msgsnd;          /* messages sent */
4947208Scael        long ru_msgrcv;          /* messages received */
5047208Scael        long ru_nsignals;        /* signals received */
5147208Scael        long ru_nvcsw;           /* voluntary context switches */
5247208Scael        long ru_nivcsw;          /* involuntary context switches */
5320145Smckusick};
5447208Scael.Ed
5547208Scael.Pp
5620145SmckusickThe fields are interpreted as follows:
5747208Scael.Bl -tag -width ru_minfltaa
5847208Scael.It Fa ru_utime
5920145Smckusickthe total amount of time spent executing in user mode.
6047208Scael.It Fa ru_stime
6120145Smckusickthe total amount of time spent in the system executing on behalf
6220145Smckusickof the process(es).
6347208Scael.It Fa ru_maxrss
6420145Smckusickthe maximum resident set size utilized (in kilobytes).
6547208Scael.It Fa ru_ixrss
6620145Smckusickan \*(lqintegral\*(rq value indicating the amount of memory used
6728085Skarelsby the text segment
6823807Ssechrestthat was also shared among other processes.  This value is expressed
6930779Sbosticin units of kilobytes * ticks-of-execution.
7047208Scael.It Fa ru_idrss
7120145Smckusickan integral value of the amount of unshared memory residing in the
7220145Smckusickdata segment of a process (expressed in units of
7330779Sbostickilobytes * ticks-of-execution).
7447208Scael.It Fa ru_isrss
7520145Smckusickan integral value of the amount of unshared memory residing in the
7620145Smckusickstack segment of a process (expressed in units of
7730779Sbostickilobytes * ticks-of-execution).
7847208Scael.It Fa ru_minflt
7928085Skarelsthe number of page faults serviced without any I/O activity; here
8028085SkarelsI/O activity is avoided by \*(lqreclaiming\*(rq a page frame from
8120145Smckusickthe list of pages awaiting reallocation.
8247208Scael.It Fa ru_majflt
8328085Skarelsthe number of page faults serviced that required I/O activity.
8447208Scael.It Fa ru_nswap
8520145Smckusickthe number of times a process was \*(lqswapped\*(rq out of main
8620145Smckusickmemory.
8747208Scael.It Fa ru_inblock
8820145Smckusickthe number of times the file system had to perform input.
8947208Scael.It Fa ru_oublock
9020145Smckusickthe number of times the file system had to perform output.
9147208Scael.It Fa ru_msgsnd
9228085Skarelsthe number of IPC messages sent.
9347208Scael.It Fa ru_msgrcv
9428085Skarelsthe number of IPC messages received.
9547208Scael.It Fa ru_nsignals
9620145Smckusickthe number of signals delivered.
9747208Scael.It Fa ru_nvcsw
9820145Smckusickthe number of times a context switch resulted due to a process
9920145Smckusickvoluntarily giving up the processor before its time slice was
10020145Smckusickcompleted (usually to await availability of a resource).
10147208Scael.It Fa ru_nivcsw
10220145Smckusickthe number of times a context switch resulted due to a higher
10320145Smckusickpriority process becoming runnable or because the current process
10420145Smckusickexceeded its time slice.
10547208Scael.El
10647208Scael.Sh NOTES
10720145SmckusickThe numbers
10847208Scael.Fa ru_inblock
10920145Smckusickand
11047208Scael.Fa ru_oublock
11120145Smckusickaccount only for real
11228085SkarelsI/O; data supplied by the caching mechanism is charged only
11320145Smckusickto the first process to read or write the data.
11447208Scael.Sh ERRORS
11547208Scael.Fn Getrusage
11637125Sbosticreturns -1 on error.
11737125SbosticThe possible errors are:
11847208Scael.Bl -tag -width Er
11947208Scael.It Bq Er EINVAL
12024440SmckusickThe
12147208Scael.Fa who
12224440Smckusickparameter is not a valid value.
12347208Scael.It Bq Er EFAULT
12424440SmckusickThe address specified by the
12547208Scael.Fa rusage
12624440Smckusickparameter is not in a valid part of the process address space.
12747208Scael.El
12847208Scael.Sh SEE ALSO
12947208Scael.Xr gettimeofday 2 ,
13047208Scael.Xr wait 2
13147208Scael.Sh BUGS
13220145SmckusickThere is no way to obtain information about a child process
13323807Ssechrestthat has not yet terminated.
13447208Scael.Sh HISTORY
13547208ScaelThe
13647208Scael.Nm
13747208Scaelfunction call appeared in
13847208Scael.Bx 4.2 .
139