1getrusage(2)                  System Calls Manual                 getrusage(2)
2
3
4

NAME

6       getrusage - get resource usage
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/resource.h>
13
14       int getrusage(int who, struct rusage *usage);
15

DESCRIPTION

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

RETURN VALUE

123       On success, zero is returned.  On error, -1 is returned, and  errno  is
124       set to indicate the error.
125

ERRORS

127       EFAULT usage points outside the accessible address space.
128
129       EINVAL who is invalid.
130

ATTRIBUTES

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

STANDARDS

142       POSIX.1-2008.
143
144       POSIX.1 specifies getrusage(), but specifies only the  fields  ru_utime
145       and ru_stime.
146
147       RUSAGE_THREAD is Linux-specific.
148

HISTORY

150       POSIX.1-2001, SVr4, 4.3BSD.
151
152       Before  Linux  2.6.9,  if  the disposition of SIGCHLD is set to SIG_IGN
153       then the resource usages of child processes are automatically  included
154       in   the  value  returned  by  RUSAGE_CHILDREN,  although  POSIX.1-2001
155       explicitly prohibits this.  This nonconformance is rectified  in  Linux
156       2.6.9 and later.
157
158       The structure definition shown at the start of this page was taken from
159       4.3BSD Reno.
160
161       Ancient systems provided a vtimes() function with a similar purpose  to
162       getrusage().   For  backward compatibility, glibc (up until Linux 2.32)
163       also provides vtimes().  All new applications should be  written  using
164       getrusage().   (Since  Linux 2.33, glibc no longer provides an vtimes()
165       implementation.)
166

NOTES

168       Resource usage metrics are preserved across an execve(2).
169
170       See also the description of /proc/pid/stat in proc(5).
171

SEE ALSO

173       clock_gettime(2), getrlimit(2), times(2), wait(2), wait4(2), clock(3)
174
175
176
177Linux man-pages 6.05              2023-07-20                      getrusage(2)
Impressum