]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/times.2
grantpt.3: SYNOPSIS: Explicitly show #define _XOPEN_SOURCE requirement
[thirdparty/man-pages.git] / man2 / times.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt (michael@moria.de)
26 .\" Modified Sat Jul 24 14:29:17 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Modified 961203 and 001211 and 010326 by aeb@cwi.nl
28 .\" Modified 001213 by Michael Haardt (michael@moria.de)
29 .\" Modified 13 Jun 02, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Added note on nonstandard behavior when SIGCHLD is ignored.
31 .\" Modified 2004-11-16, mtk, Noted that the nonconformance when
32 .\" SIGCHLD is being ignored is fixed in 2.6.9; other minor changes
33 .\" Modified 2004-12-08, mtk, in 2.6 times() return value changed
34 .\" 2005-04-13, mtk
35 .\" Added notes on nonstandard behavior: Linux allows 'buf' to
36 .\" be NULL, but POSIX.1 doesn't specify this and it's nonportable.
37 .\"
38 .TH TIMES 2 2017-09-15 "Linux" "Linux Programmer's Manual"
39 .SH NAME
40 times \- get process times
41 .SH SYNOPSIS
42 .B #include <sys/times.h>
43 .PP
44 .BI "clock_t times(struct tms *" buf );
45 .SH DESCRIPTION
46 .BR times ()
47 stores the current process times in the
48 .I "struct tms"
49 that
50 .I buf
51 points to.
52 The
53 .I struct tms
54 is as defined in
55 .IR <sys/times.h> :
56 .PP
57 .in +4n
58 .EX
59 struct tms {
60 clock_t tms_utime; /* user time */
61 clock_t tms_stime; /* system time */
62 clock_t tms_cutime; /* user time of children */
63 clock_t tms_cstime; /* system time of children */
64 };
65 .EE
66 .in
67 .PP
68 The
69 .I tms_utime
70 field contains the CPU time spent executing instructions
71 of the calling process.
72 The
73 .I tms_stime
74 field contains the CPU time spent executing inside the kernel
75 while performing tasks on behalf of the calling process.
76 .PP
77 The
78 .I tms_cutime
79 field contains the sum of the
80 .I tms_utime
81 and
82 .I tms_cutime
83 values for all waited-for terminated children.
84 The
85 .I tms_cstime
86 field contains the sum of the
87 .I tms_stime
88 and
89 .I tms_cstime
90 values for all waited-for terminated children.
91 .PP
92 Times for terminated children (and their descendants)
93 are added in at the moment
94 .BR wait (2)
95 or
96 .BR waitpid (2)
97 returns their process ID.
98 In particular, times of grandchildren
99 that the children did not wait for are never seen.
100 .PP
101 All times reported are in clock ticks.
102 .SH RETURN VALUE
103 .BR times ()
104 returns the number of clock ticks that have elapsed since
105 an arbitrary point in the past.
106 The return value may overflow the possible range of type
107 .IR clock_t .
108 On error, \fI(clock_t)\ \-1\fP is returned, and
109 .I errno
110 is set appropriately.
111 .SH ERRORS
112 .TP
113 .B EFAULT
114 .I tms
115 points outside the process's address space.
116 .SH CONFORMING TO
117 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
118 .SH NOTES
119 The number of clock ticks per second can be obtained using:
120 .PP
121 .in +4n
122 .EX
123 sysconf(_SC_CLK_TCK);
124 .EE
125 .in
126 .PP
127 In POSIX.1-1996 the symbol \fBCLK_TCK\fP (defined in
128 .IR <time.h> )
129 is mentioned as obsolescent.
130 It is obsolete now.
131 .PP
132 In Linux kernel versions before 2.6.9,
133 if the disposition of
134 .B SIGCHLD
135 is set to
136 .BR SIG_IGN ,
137 then the times of terminated children
138 are automatically included in the
139 .I tms_cstime
140 and
141 .I tms_cutime
142 fields, although POSIX.1-2001 says that this should happen
143 only if the calling process
144 .BR wait (2)s
145 on its children.
146 This nonconformance is rectified in Linux 2.6.9 and later.
147 .\" See the description of times() in XSH, which says:
148 .\" The times of a terminated child process are included... when wait()
149 .\" or waitpid() returns the process ID of this terminated child.
150 .PP
151 On Linux, the
152 .I buf
153 argument can be specified as NULL, with the result that
154 .BR times ()
155 just returns a function result.
156 However, POSIX does not specify this behavior, and most
157 other UNIX implementations require a non-NULL value for
158 .IR buf .
159 .PP
160 Note that
161 .BR clock (3)
162 also returns a value of type
163 .IR clock_t ,
164 but this value is measured in units of
165 .BR CLOCKS_PER_SEC ,
166 not the clock ticks used by
167 .BR times ().
168 .PP
169 On Linux, the "arbitrary point in the past" from which the return value of
170 .BR times ()
171 is measured has varied across kernel versions.
172 On Linux 2.4 and earlier, this point is the moment the system was booted.
173 Since Linux 2.6, this point is \fI(2^32/HZ) \- 300\fP
174 seconds before system boot time.
175 This variability across kernel versions (and across UNIX implementations),
176 combined with the fact that the returned value may overflow the range of
177 .IR clock_t ,
178 means that a portable application would be wise to avoid using this value.
179 To measure changes in elapsed time, use
180 .BR clock_gettime (2)
181 instead.
182 .\" .PP
183 .\" On older systems the number of clock ticks per second is given
184 .\" by the variable HZ.
185 .SS Historical
186 SVr1-3 returns
187 .I long
188 and the struct members are of type
189 .I time_t
190 although they store clock ticks, not seconds since the Epoch.
191 V7 used
192 .I long
193 for the struct members, because it had no type
194 .I time_t
195 yet.
196 .SH BUGS
197 A limitation of the Linux system call conventions on some architectures
198 (notably i386) means that on Linux 2.6 there is a small time window
199 (41 seconds) soon after boot when
200 .BR times ()
201 can return \-1, falsely indicating that an error occurred.
202 The same problem can occur when the return value wraps past
203 the maximum value that can be stored in
204 .BR clock_t .
205 .\" The problem is that a syscall return of -4095 to -1
206 .\" is interpreted by glibc as an error, and the wrapper converts
207 .\" the return value to -1.
208 .\" http://marc.info/?l=linux-kernel&m=119447727031225&w=2
209 .\" "compat_sys_times() bogus until jiffies >= 0"
210 .\" November 2007
211 .SH SEE ALSO
212 .BR time (1),
213 .BR getrusage (2),
214 .BR wait (2),
215 .BR clock (3),
216 .BR sysconf (3),
217 .BR time (7)