1GETRUSAGE(2)               Linux Programmer's Manual              GETRUSAGE(2)
2
3
4

NAME

6       getrusage - get resource usage
7

SYNOPSIS

9       #include <sys/time.h>
10       #include <sys/resource.h>
11
12       int getrusage(int who, struct rusage *usage);
13

DESCRIPTION

15       getrusage()  returns  resource usage measures for who, which can be one
16       of the following:
17
18       RUSAGE_SELF
19              Return resource usage statistics for the calling process,  which
20              is the sum of resources used by all threads in the process.
21
22       RUSAGE_CHILDREN
23              Return resource usage statistics for all children of the calling
24              process that have terminated and been waited for.  These statis‐
25              tics  will include the resources used by grandchildren, and fur‐
26              ther removed descendants, if all of the intervening  descendants
27              waited on their terminated children.
28
29       RUSAGE_THREAD (since Linux 2.6.26)
30              Return resource usage statistics for the calling thread.
31
32       The  resource usages are returned in the structure pointed to by usage,
33       which has the following form:
34
35           struct rusage {
36               struct timeval ru_utime; /* user time used */
37               struct timeval ru_stime; /* system time used */
38               long   ru_maxrss;        /* maximum resident set size */
39               long   ru_ixrss;         /* integral shared memory size */
40               long   ru_idrss;         /* integral unshared data size */
41               long   ru_isrss;         /* integral unshared stack size */
42               long   ru_minflt;        /* page reclaims */
43               long   ru_majflt;        /* page faults */
44               long   ru_nswap;         /* swaps */
45               long   ru_inblock;       /* block input operations */
46               long   ru_oublock;       /* block output operations */
47               long   ru_msgsnd;        /* messages sent */
48               long   ru_msgrcv;        /* messages received */
49               long   ru_nsignals;      /* signals received */
50               long   ru_nvcsw;         /* voluntary context switches */
51               long   ru_nivcsw;        /* involuntary context switches */
52           };
53

RETURN VALUE

55       On success, zero is returned.  On error, -1 is returned, and  errno  is
56       set appropriately.
57

ERRORS

59       EFAULT usage points outside the accessible address space.
60
61       EINVAL who is invalid.
62

CONFORMING TO

64       SVr4,  4.3BSD.   POSIX.1-2001 specifies getrusage(), but only specifies
65       the fields ru_utime and ru_stime.
66
67       RUSAGE_THREAD is Linux-specific.
68

NOTES

70       Resource usage metrics are preserved across an execve(2).
71
72       Including <sys/time.h> is not required these days, but increases porta‐
73       bility.  (Indeed, struct timeval is defined in <sys/time.h>.)
74
75       In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
76       set to SIG_IGN then the resource usages of child processes are automat‐
77       ically  included  in  the  value  returned by RUSAGE_CHILDREN, although
78       POSIX.1-2001 explicitly prohibits this.  This non-conformance is recti‐
79       fied in Linux 2.6.9 and later.
80
81       The structure definition shown at the start of this page was taken from
82       4.3BSD Reno.  Not all fields are meaningful under Linux.  In Linux  2.4
83       only  the fields ru_utime, ru_stime, ru_minflt, and ru_majflt are main‐
84       tained.  Since Linux 2.6, ru_nvcsw and ru_nivcsw are also maintained.
85
86       See also the description of /proc/PID/stat in proc(5).
87

SEE ALSO

89       clock_gettime(2), getrlimit(2), times(2), wait(2), wait4(2), clock(3)
90

COLOPHON

92       This page is part of release 3.22 of the Linux  man-pages  project.   A
93       description  of  the project, and information about reporting bugs, can
94       be found at http://www.kernel.org/doc/man-pages/.
95
96
97
98Linux                             2008-10-06                      GETRUSAGE(2)
Impressum