Go to the previous, next section.

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:

Just the current process.

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.

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
User time used.

struct timeval ru_stime
System time used.

long ru_majflt
Number of page faults.

long ru_inblock
Number of block input operations.

long ru_oublock
Number of block output operations.

long ru_msgsnd
Number of messages sent.

long ru_msgrcv
Number of messages received.

long ru_nsignals
Number of signals received.

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 previous, next section.