]>
Commit | Line | Data |
---|---|---|
e3a887db MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" Copyright (c) 1992 Drew Eckhardt, March 28, 1992 | |
6883b3e7 | 4 | .\" and Copyright (c) 2002 Michael Kerrisk |
e3a887db MK |
5 | .\" |
6 | .\" Permission is granted to make and distribute verbatim copies of this | |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
e3a887db MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
e3a887db MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
25 | .\" | |
c13182ef MK |
26 | .\" 2004-11-16 -- mtk: the getrlimit.2 page, which formerly included |
27 | .\" coverage of getrusage(2), has been split, so that the latter is | |
28 | .\" now covered in its own getrusage.2. For older details of change | |
0967c11f | 29 | .\" history, etc., see getrlimit.2 |
e3a887db MK |
30 | .\" |
31 | .\" Modified 2004-11-16, mtk, Noted that the non-conformance | |
32 | .\" when SIGCHLD is being ignored is fixed in 2.6.9. | |
94ce95ef MK |
33 | .\" 2008-02-22, Sripathi Kodi <sripathik@in.ibm.com>: Document RUSAGE_THREAD |
34 | .\" 2008-05-25, mtk, clarify RUSAGE_CHILDREN + other clean-ups. | |
e3a887db | 35 | .\" |
6f6a9bc7 | 36 | .TH GETRUSAGE 2 2009-08-25 "Linux" "Linux Programmer's Manual" |
e3a887db MK |
37 | .SH NAME |
38 | getrusage \- get resource usage | |
39 | .SH SYNOPSIS | |
40 | .B #include <sys/time.h> | |
41 | .br | |
42 | .B #include <sys/resource.h> | |
43 | .sp | |
44 | .BI "int getrusage(int " who ", struct rusage *" usage ); | |
45 | .SH DESCRIPTION | |
46 | .PP | |
47 | .BR getrusage () | |
94ce95ef MK |
48 | returns resource usage measures for |
49 | .IR who , | |
50 | which can be one of the following: | |
51 | .TP | |
2914a14d MK |
52 | .B RUSAGE_SELF |
53 | Return resource usage statistics for the calling process, | |
94ce95ef MK |
54 | which is the sum of resources used by all threads in the process. |
55 | .TP | |
2914a14d | 56 | .B RUSAGE_CHILDREN |
94ce95ef MK |
57 | Return resource usage statistics for all children of the |
58 | calling process that have terminated and been waited for. | |
59 | These statistics will include the resources used by grandchildren, | |
60 | and further removed descendants, | |
61 | if all of the intervening descendants waited on their terminated children. | |
62 | .TP | |
63 | .BR RUSAGE_THREAD " (since Linux 2.6.26)" | |
64 | Return resource usage statistics for the calling thread. | |
65 | .PP | |
66 | The resource usages are returned in the structure pointed to by | |
67 | .IR usage , | |
68 | which has the following form: | |
c13182ef | 69 | .PP |
a08ea57c | 70 | .in +4n |
e3a887db MK |
71 | .nf |
72 | struct rusage { | |
73 | struct timeval ru_utime; /* user time used */ | |
74 | struct timeval ru_stime; /* system time used */ | |
75 | long ru_maxrss; /* maximum resident set size */ | |
76 | long ru_ixrss; /* integral shared memory size */ | |
77 | long ru_idrss; /* integral unshared data size */ | |
78 | long ru_isrss; /* integral unshared stack size */ | |
79 | long ru_minflt; /* page reclaims */ | |
80 | long ru_majflt; /* page faults */ | |
81 | long ru_nswap; /* swaps */ | |
82 | long ru_inblock; /* block input operations */ | |
83 | long ru_oublock; /* block output operations */ | |
84 | long ru_msgsnd; /* messages sent */ | |
85 | long ru_msgrcv; /* messages received */ | |
86 | long ru_nsignals; /* signals received */ | |
87 | long ru_nvcsw; /* voluntary context switches */ | |
88 | long ru_nivcsw; /* involuntary context switches */ | |
89 | }; | |
90 | .fi | |
a08ea57c | 91 | .in |
e3a887db | 92 | .SH "RETURN VALUE" |
c13182ef MK |
93 | On success, zero is returned. |
94 | On error, \-1 is returned, and | |
e3a887db MK |
95 | .I errno |
96 | is set appropriately. | |
97 | .SH ERRORS | |
98 | .TP | |
99 | .B EFAULT | |
100 | .I usage | |
101 | points outside the accessible address space. | |
102 | .TP | |
103 | .B EINVAL | |
104 | .I who | |
105 | is invalid. | |
106 | .SH "CONFORMING TO" | |
c13182ef MK |
107 | SVr4, 4.3BSD. |
108 | POSIX.1-2001 specifies | |
97c1eac8 MK |
109 | .BR getrusage (), |
110 | but only specifies the fields | |
111 | .I ru_utime | |
112 | and | |
113 | .IR ru_stime . | |
94ce95ef MK |
114 | |
115 | .B RUSAGE_THREAD | |
116 | is Linux-specific. | |
e3a887db | 117 | .SH NOTES |
dfcc37a6 MK |
118 | Resource usage metrics are preserved across an |
119 | .BR execve (2). | |
120 | ||
e3a887db MK |
121 | Including |
122 | .I <sys/time.h> | |
123 | is not required these days, but increases portability. | |
124 | (Indeed, | |
125 | .I struct timeval | |
126 | is defined in | |
127 | .IR <sys/time.h> .) | |
128 | .PP | |
129 | In Linux kernel versions before 2.6.9, if the disposition of | |
130 | .B SIGCHLD | |
131 | is set to | |
132 | .B SIG_IGN | |
133 | then the resource usages of child processes | |
134 | are automatically included in the value returned by | |
135 | .BR RUSAGE_CHILDREN , | |
97c1eac8 | 136 | although POSIX.1-2001 explicitly prohibits this. |
e3a887db MK |
137 | This non-conformance is rectified in Linux 2.6.9 and later. |
138 | .\" See the description of getrusage() in XSH. | |
139 | .\" A similar statement was also in SUSv2. | |
140 | .LP | |
bc5ec131 MK |
141 | The structure definition shown at the start of this page |
142 | was taken from 4.3BSD Reno. | |
e3a887db | 143 | Not all fields are meaningful under Linux. |
bc5ec131 | 144 | In Linux 2.4 only the fields |
dd61d68c MK |
145 | .IR ru_utime , |
146 | .IR ru_stime , | |
147 | .IR ru_minflt , | |
e3a887db | 148 | and |
0daa9e92 | 149 | .I ru_majflt |
e3a887db | 150 | are maintained. |
c13182ef | 151 | Since Linux 2.6, |
dd61d68c MK |
152 | .I ru_nvcsw |
153 | and | |
154 | .I ru_nivcsw | |
155 | are also maintained. | |
6f6a9bc7 MK |
156 | Since Linux 2.6.22, |
157 | .I ru_inblock | |
158 | and | |
159 | .I ru_oublock | |
160 | are also maintained. | |
94ce95ef MK |
161 | |
162 | See also the description of | |
163 | .IR /proc/PID/stat | |
164 | in | |
165 | .BR proc (5). | |
e3a887db | 166 | .SH "SEE ALSO" |
0eb44391 | 167 | .BR clock_gettime (2), |
e3a887db MK |
168 | .BR getrlimit (2), |
169 | .BR times (2), | |
170 | .BR wait (2), | |
0302f101 | 171 | .BR wait4 (2), |
0eb44391 | 172 | .BR clock (3) |