Go to the first, previous, next, last section, table of contents.


Resource Usage

The function getrusage and the data type struct rusage are used for examining the usage figures of a process. They are declared in `sys/resource.h'.

Function: int getrusage (int processes, struct rusage *rusage)
This function reports the usage totals for processes specified by processes, storing the information in *rusage.

In most systems, processes has only two valid values:

RUSAGE_SELF
Just the current process.
RUSAGE_CHILDREN
All child processes (direct and indirect) that have terminated already.

In the GNU system, you can also inquire about a particular child process by specifying its process ID.

The return value of getrusage is zero for success, and -1 for failure.

EINVAL
The argument processes is not valid.

One way of getting usage figures for a particular child process is with the function wait4, which returns totals for a child when it terminates. See section BSD Process Wait Functions.

Data Type: struct rusage
This data type records a collection usage amounts for various sorts of resources. It has the following members, and possibly others:

struct timeval ru_utime
Time spent executing user instructions.
struct timeval ru_stime
Time spent in operating system code on behalf of processes.
long int ru_maxrss
The maximum resident set size used, in kilobytes. That is, the maximum number of kilobytes that processes used in real memory simultaneously.
long int ru_ixrss
An integral value expressed in kilobytes times ticks of execution, which indicates the amount of memory used by text that was shared with other processes.
long int ru_idrss
An integral value expressed the same way, which is the amount of unshared memory used in data.
long int ru_isrss
An integral value expressed the same way, which is the amount of unshared memory used in stack space.
long int ru_minflt
The number of page faults which were serviced without requiring any I/O.
long int ru_majflt
The number of page faults which were serviced by doing I/O.
long int ru_nswap
The number of times processes was swapped entirely out of main memory.
long int ru_inblock
The number of times the file system had to read from the disk on behalf of processes.
long int ru_oublock
The number of times the file system had to write to the disk on behalf of processes.
long int ru_msgsnd
Number of IPC messages sent.
long ru_msgrcv
Number of IPC messages received.
long int ru_nsignals
Number of signals received.
long int ru_nvcsw
The number of times processes voluntarily invoked a context switch (usually to wait for some service).
long int ru_nivcsw
The number of times an involuntary context switch took place (because the time slice expired, or another process of higher priority became runnable).

An additional historical function for examining usage figures, vtimes, is supported but not documented here. It is declared in `sys/vtimes.h'.


Go to the first, previous, next, last section, table of contents.