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

NAME

6       getrusage - get resource usage
7

SYNOPSIS

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

DESCRIPTION

14       getrusage()  returns  resource usage measures for who, which can be one
15       of the following:
16
17       RUSAGE_SELF
18              Return resource usage statistics for the calling process,  which
19              is the sum of resources used by all threads in the process.
20
21       RUSAGE_CHILDREN
22              Return resource usage statistics for all children of the calling
23              process that have terminated and been waited for.  These statis‐
24              tics  will include the resources used by grandchildren, and fur‐
25              ther removed descendants, if all of the intervening  descendants
26              waited on their terminated children.
27
28       RUSAGE_THREAD (since Linux 2.6.26)
29              Return  resource  usage  statistics for the calling thread.  The
30              _GNU_SOURCE feature test macro must be defined (before including
31              any  header file) in order to obtain the definition of this con‐
32              stant from <sys/resource.h>.
33
34       The resource usages are returned in the structure pointed to by  usage,
35       which has the following form:
36
37           struct rusage {
38               struct timeval ru_utime; /* user CPU time used */
39               struct timeval ru_stime; /* system CPU time used */
40               long   ru_maxrss;        /* maximum resident set size */
41               long   ru_ixrss;         /* integral shared memory size */
42               long   ru_idrss;         /* integral unshared data size */
43               long   ru_isrss;         /* integral unshared stack size */
44               long   ru_minflt;        /* page reclaims (soft page faults) */
45               long   ru_majflt;        /* page faults (hard page faults) */
46               long   ru_nswap;         /* swaps */
47               long   ru_inblock;       /* block input operations */
48               long   ru_oublock;       /* block output operations */
49               long   ru_msgsnd;        /* IPC messages sent */
50               long   ru_msgrcv;        /* IPC messages received */
51               long   ru_nsignals;      /* signals received */
52               long   ru_nvcsw;         /* voluntary context switches */
53               long   ru_nivcsw;        /* involuntary context switches */
54           };
55
56       Not  all  fields  are completed; unmaintained fields are set to zero by
57       the kernel.  (The unmaintained fields are  provided  for  compatibility
58       with  other  systems,  and  because  they  may  one day be supported on
59       Linux.)  The fields are interpreted as follows:
60
61       ru_utime
62              This is the total amount of time spent executing in  user  mode,
63              expressed in a timeval structure (seconds plus microseconds).
64
65       ru_stime
66              This is the total amount of time spent executing in kernel mode,
67              expressed in a timeval structure (seconds plus microseconds).
68
69       ru_maxrss (since Linux 2.6.32)
70              This is the maximum resident set size used (in kilobytes).   For
71              RUSAGE_CHILDREN,  this  is  the resident set size of the largest
72              child, not the maximum resident set size of the process tree.
73
74       ru_ixrss (unmaintained)
75              This field is currently unused on Linux.
76
77       ru_idrss (unmaintained)
78              This field is currently unused on Linux.
79
80       ru_isrss (unmaintained)
81              This field is currently unused on Linux.
82
83       ru_minflt
84              The number of page faults serviced  without  any  I/O  activity;
85              here  I/O  activity is avoided by “reclaiming” a page frame from
86              the list of pages awaiting reallocation.
87
88       ru_majflt
89              The number of page faults serviced that required I/O activity.
90
91       ru_nswap (unmaintained)
92              This field is currently unused on Linux.
93
94       ru_inblock (since Linux 2.6.22)
95              The number of times the filesystem had to perform input.
96
97       ru_oublock (since Linux 2.6.22)
98              The number of times the filesystem had to perform output.
99
100       ru_msgsnd (unmaintained)
101              This field is currently unused on Linux.
102
103       ru_msgrcv (unmaintained)
104              This field is currently unused on Linux.
105
106       ru_nsignals (unmaintained)
107              This field is currently unused on Linux.
108
109       ru_nvcsw (since Linux 2.6)
110              The number of times a context switch resulted due to  a  process
111              voluntarily  giving  up  the processor before its time slice was
112              completed (usually to await availability of a resource).
113
114       ru_nivcsw (since Linux 2.6)
115              The number of times a context switch resulted due  to  a  higher
116              priority  process  becoming  runnable  or  because  the  current
117              process exceeded its time slice.
118

RETURN VALUE

120       On success, zero is returned.  On error, -1 is returned, and  errno  is
121       set to indicate the error.
122

ERRORS

124       EFAULT usage points outside the accessible address space.
125
126       EINVAL who is invalid.
127

ATTRIBUTES

129       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
130       tributes(7).
131
132       ┌────────────────────────────────────────────┬───────────────┬─────────┐
133Interface                                   Attribute     Value   
134       ├────────────────────────────────────────────┼───────────────┼─────────┤
135getrusage()                                 │ Thread safety │ MT-Safe │
136       └────────────────────────────────────────────┴───────────────┴─────────┘
137

CONFORMING TO

139       POSIX.1-2001,   POSIX.1-2008,   SVr4,   4.3BSD.    POSIX.1    specifies
140       getrusage(), but specifies only the fields ru_utime and ru_stime.
141
142       RUSAGE_THREAD is Linux-specific.
143

NOTES

145       Resource usage metrics are preserved across an execve(2).
146
147       In Linux kernel versions before 2.6.9, if the disposition of SIGCHLD is
148       set to SIG_IGN then the resource usages of child processes are automat‐
149       ically  included  in  the  value  returned by RUSAGE_CHILDREN, although
150       POSIX.1-2001 explicitly prohibits this.  This nonconformance is  recti‐
151       fied in Linux 2.6.9 and later.
152
153       The structure definition shown at the start of this page was taken from
154       4.3BSD Reno.
155
156       Ancient systems provided a vtimes() function with a similar purpose  to
157       getrusage().  For backward compatibility, glibc (up until version 2.32)
158       also provides vtimes().  All new applications should be  written  using
159       getrusage().  (Since version 2.33, glibc no longer provides an vtimes()
160       implementation.)
161
162       See also the description of /proc/[pid]/stat in proc(5).
163

SEE ALSO

165       clock_gettime(2), getrlimit(2), times(2), wait(2), wait4(2), clock(3)
166

COLOPHON

168       This page is part of release 5.13 of the Linux  man-pages  project.   A
169       description  of  the project, information about reporting bugs, and the
170       latest    version    of    this    page,    can     be     found     at
171       https://www.kernel.org/doc/man-pages/.
172
173
174
175Linux                             2021-03-22                      GETRUSAGE(2)
Impressum