Node:Resource Usage,
Next:Limits on Resources,
Up:Resource Usage And Limitation
Resource Usage
The function getrusage and the data type struct rusage
are used to examine the resource usage of a process.  They are declared
in sys/resource.h.
| int getrusage (int processes, struct rusage *rusage) | Function | 
| This function reports resource usage totals for processes specified by
processes, storing the information in *rusage.In most systems, processes has only two valid values:
 
RUSAGE_SELFJust the current process.
RUSAGE_CHILDRENAll child processes (direct and indirect) that have already terminated. 
 In the GNU system, you can also inquire about a particular child process
by specifying its process ID.
 The return value of getrusageis zero for success, and-1for failure. 
EINVALThe argument processes is not valid. 
 | 
One way of getting resource usage for a particular child process is with
the function wait4, which returns totals for a child when it
terminates.  See BSD Wait Functions.
| This data type stores various resource usage statistics.  It has the
following members, and possibly others: 
struct timeval ru_utimeTime spent executing user instructions.
struct timeval ru_stimeTime spent in operating system code on behalf of processes.
long int ru_maxrssThe maximum resident set size used, in kilobytes.  That is, the maximum
number of kilobytes of physical memory that processes used
simultaneously.
long int ru_ixrssAn 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_idrssAn integral value expressed the same way, which is the amount of
unshared memory used for data.
long int ru_isrssAn integral value expressed the same way, which is the amount of
unshared memory used for stack space.
long int ru_minfltThe number of page faults which were serviced without requiring any I/O.
long int ru_majfltThe number of page faults which were serviced by doing I/O.
long int ru_nswapThe number of times processes was swapped entirely out of main memory.
long int ru_inblockThe number of times the file system had to read from the disk on behalf
of processes.
long int ru_oublockThe number of times the file system had to write to the disk on behalf
of processes.
long int ru_msgsndNumber of IPC messages sent.
long int ru_msgrcvNumber of IPC messages received.
long int ru_nsignalsNumber of signals received.
long int ru_nvcswThe number of times processes voluntarily invoked a context switch
(usually to wait for some service).
long int ru_nivcswThe number of times an involuntary context switch took place (because
a time slice expired, or another process of higher priority was
scheduled). 
 | 
vtimes is a historical function that does some of what
getrusage does.  getrusage is a better choice.
vtimes and its vtimes data structure are declared in
sys/vtimes.h.
| int vtimes (struct vtimes current, struct vtimes child) | Function | 
| vtimesreports resource usage totals for a process.
 If current is non-null, vtimesstores resource usage totals for
the invoking process alone in the structure to which it points.  If
child is non-null,vtimesstores resource usage totals for all
past children (which have terminated) of the invoking process in the structure
to which it points. 
 
| This data type contains information about the resource usage of a process. 
Each member corresponds to a member of the struct rusagedata type
described above.
vm_utimeUser CPU time.  Analogous to ru_utimeinstruct rusage
vm_stimeSystem CPU time.  Analogous to ru_stimeinstruct rusage
vm_idsrssData and stack memory.  The sum of the values that would be reported as
ru_idrssandru_isrssinstruct rusage
vm_ixrssShared memory.  Analogous to ru_ixrssinstruct rusage
vm_maxrssMaximent resident set size.  Analogous to ru_maxrssinstruct rusage
vm_majfltMajor page faults.  Analogous to ru_majfltinstruct rusage
vm_minfltMinor page faults.  Analogous to ru_minfltinstruct rusage
vm_nswapSwap count.  Analogous to ru_nswapinstruct rusage
vm_inblkDisk reads.  Analogous to ru_inblkinstruct rusage
vm_oublkDisk writes.  Analogous to ru_oublkinstruct rusage |  The return value is zero if the function succeeds; -1otherwise. | 
An additional historical function for examining resource usage,
vtimes, is supported but not documented here.  It is declared in
sys/vtimes.h.