1getrusage(2) System Calls Manual getrusage(2)
2
3
4
6 getrusage - get resource usage
7
9 Standard C library (libc, -lc)
10
12 #include <sys/resource.h>
13
14 int getrusage(int who, struct rusage *usage);
15
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.