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 CPU time used */
37               struct timeval ru_stime; /* system CPU 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 (soft page faults) */
43               long   ru_majflt;        /* page faults (hard 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;        /* IPC messages sent */
48               long   ru_msgrcv;        /* IPC messages received */
49               long   ru_nsignals;      /* signals received */
50               long   ru_nvcsw;         /* voluntary context switches */
51               long   ru_nivcsw;        /* involuntary context switches */
52           };
53
54       Not all fields are completed; unmaintained fields are set  to  zero  by
55       the  kernel.   (The  unmaintained fields are provided for compatibility
56       with other systems, and because  they  may  one  day  be  supported  on
57       Linux.)  The fields are interpreted as follows:
58
59       ru_utime
60              This  is  the total amount of time spent executing in user mode,
61              expressed in a timeval structure (seconds plus microseconds).
62
63       ru_stime
64              This is the total amount of time spent executing in kernel mode,
65              expressed in a timeval structure (seconds plus microseconds).
66
67       ru_maxrss (since Linux 2.6.32)
68              This  is the maximum resident set size used (in kilobytes).  For
69              RUSAGE_CHILDREN, this is the resident set size  of  the  largest
70              child, not the maximum resident set size of the process tree.
71
72       ru_ixrss (unmaintained)
73              This field is currently unused on Linux.
74
75       ru_idrss (unmaintained)
76              This field is currently unused on Linux.
77
78       ru_isrss (unmaintained)
79              This field is currently unused on Linux.
80
81       ru_minflt
82              The  number  of  page  faults serviced without any I/O activity;
83              here I/O activity is avoided by “reclaiming” a page  frame  from
84              the list of pages awaiting reallocation.
85
86       ru_majflt
87              The number of page faults serviced that required I/O activity.
88
89       ru_nswap (unmaintained)
90              This field is currently unused on Linux.
91
92       ru_inblock (since Linux 2.6.22)
93              The number of times the file system had to perform input.
94
95       ru_oublock (since Linux 2.6.22)
96              The number of times the file system had to perform output.
97
98       ru_msgsnd (unmaintained)
99              This field is currently unused on Linux.
100
101       ru_msgrcv (unmaintained)
102              This field is currently unused on Linux.
103
104       ru_nsignals (unmaintained)
105              This field is currently unused on Linux.
106
107       ru_nvcsw (since Linux 2.6)
108              The  number  of times a context switch resulted due to a process
109              voluntarily giving up the processor before its  time  slice  was
110              completed (usually to await availability of a resource).
111
112       ru_nivcsw (since Linux 2.6)
113              The  number  of  times a context switch resulted due to a higher
114              priority  process  becoming  runnable  or  because  the  current
115              process exceeded its time slice.
116

RETURN VALUE

118       On  success,  zero is returned.  On error, -1 is returned, and errno is
119       set appropriately.
120

ERRORS

122       EFAULT usage points outside the accessible address space.
123
124       EINVAL who is invalid.
125

CONFORMING TO

127       SVr4, 4.3BSD.  POSIX.1-2001 specifies getrusage(), but  specifies  only
128       the fields ru_utime and ru_stime.
129
130       RUSAGE_THREAD is Linux-specific.
131

NOTES

133       Resource usage metrics are preserved across an execve(2).
134
135       Including <sys/time.h> is not required these days, but increases porta‐
136       bility.  (Indeed, struct timeval is defined in <sys/time.h>.)
137
138       In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
139       set to SIG_IGN then the resource usages of child processes are automat‐
140       ically included in the  value  returned  by  RUSAGE_CHILDREN,  although
141       POSIX.1-2001  explicitly prohibits this.  This nonconformance is recti‐
142       fied in Linux 2.6.9 and later.
143
144       The structure definition shown at the start of this page was taken from
145       4.3BSD Reno.
146
147       Ancient  systems provided a vtimes() function with a similar purpose to
148       getrusage().  For backward compatibility, glibc also provides vtimes().
149       All new applications should be written using getrusage().
150
151       See also the description of /proc/PID/stat in proc(5).
152

SEE ALSO

154       clock_gettime(2), getrlimit(2), times(2), wait(2), wait4(2), clock(3)
155

COLOPHON

157       This  page  is  part of release 3.53 of the Linux man-pages project.  A
158       description of the project, and information about reporting  bugs,  can
159       be found at http://www.kernel.org/doc/man-pages/.
160
161
162
163Linux                             2010-09-26                      GETRUSAGE(2)
Impressum