seccomp_unotify.2: tfix
[man-pages.git] / man2 / times.2
blob8294251ea11fb41ad34f99c520962448ca40add9
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 2021-03-22 "Linux" "Linux Programmer's Manual"
39 .SH NAME
40 times \- get process times
41 .SH SYNOPSIS
42 .nf
43 .B #include <sys/times.h>
44 .PP
45 .BI "clock_t times(struct tms *" buf );
46 .fi
47 .SH DESCRIPTION
48 .BR times ()
49 stores the current process times in the
50 .I "struct tms"
51 that
52 .I buf
53 points to.
54 The
55 .I struct tms
56 is as defined in
57 .IR <sys/times.h> :
58 .PP
59 .in +4n
60 .EX
61 struct tms {
62     clock_t tms_utime;  /* user time */
63     clock_t tms_stime;  /* system time */
64     clock_t tms_cutime; /* user time of children */
65     clock_t tms_cstime; /* system time of children */
67 .EE
68 .in
69 .PP
70 The
71 .I tms_utime
72 field contains the CPU time spent executing instructions
73 of the calling process.
74 The
75 .I tms_stime
76 field contains the CPU time spent executing inside the kernel
77 while performing tasks on behalf of the calling process.
78 .PP
79 The
80 .I tms_cutime
81 field contains the sum of the
82 .I tms_utime
83 and
84 .I tms_cutime
85 values for all waited-for terminated children.
86 The
87 .I tms_cstime
88 field contains the sum of the
89 .I tms_stime
90 and
91 .I tms_cstime
92 values for all waited-for terminated children.
93 .PP
94 Times for terminated children (and their descendants)
95 are added in at the moment
96 .BR wait (2)
98 .BR waitpid (2)
99 returns their process ID.
100 In particular, times of grandchildren
101 that the children did not wait for are never seen.
103 All times reported are in clock ticks.
104 .SH RETURN VALUE
105 .BR times ()
106 returns the number of clock ticks that have elapsed since
107 an arbitrary point in the past.
108 The return value may overflow the possible range of type
109 .IR clock_t .
110 On error, \fI(clock_t)\ \-1\fP is returned, and
111 .I errno
112 is set to indicate the error.
113 .SH ERRORS
115 .B EFAULT
116 .I tms
117 points outside the process's address space.
118 .SH CONFORMING TO
119 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
120 .SH NOTES
121 The number of clock ticks per second can be obtained using:
123 .in +4n
125 sysconf(_SC_CLK_TCK);
129 In POSIX.1-1996 the symbol \fBCLK_TCK\fP (defined in
130 .IR <time.h> )
131 is mentioned as obsolescent.
132 It is obsolete now.
134 In Linux kernel versions before 2.6.9,
135 if the disposition of
136 .B SIGCHLD
137 is set to
138 .BR SIG_IGN ,
139 then the times of terminated children
140 are automatically included in the
141 .I tms_cstime
143 .I tms_cutime
144 fields, although POSIX.1-2001 says that this should happen
145 only if the calling process
146 .BR wait (2)s
147 on its children.
148 This nonconformance is rectified in Linux 2.6.9 and later.
149 .\" See the description of times() in XSH, which says:
150 .\"     The times of a terminated child process are included... when wait()
151 .\"     or waitpid() returns the process ID of this terminated child.
153 On Linux, the
154 .I buf
155 argument can be specified as NULL, with the result that
156 .BR times ()
157 just returns a function result.
158 However, POSIX does not specify this behavior, and most
159 other UNIX implementations require a non-NULL value for
160 .IR buf .
162 Note that
163 .BR clock (3)
164 also returns a value of type
165 .IR clock_t ,
166 but this value is measured in units of
167 .BR CLOCKS_PER_SEC ,
168 not the clock ticks used by
169 .BR times ().
171 On Linux, the "arbitrary point in the past" from which the return value of
172 .BR times ()
173 is measured has varied across kernel versions.
174 On Linux 2.4 and earlier, this point is the moment the system was booted.
175 Since Linux 2.6, this point is \fI(2^32/HZ) \- 300\fP
176 seconds before system boot time.
177 This variability across kernel versions (and across UNIX implementations),
178 combined with the fact that the returned value may overflow the range of
179 .IR clock_t ,
180 means that a portable application would be wise to avoid using this value.
181 To measure changes in elapsed time, use
182 .BR clock_gettime (2)
183 instead.
184 .\" .PP
185 .\" On older systems the number of clock ticks per second is given
186 .\" by the variable HZ.
187 .SS Historical
188 SVr1-3 returns
189 .I long
190 and the struct members are of type
191 .I time_t
192 although they store clock ticks, not seconds since the Epoch.
193 V7 used
194 .I long
195 for the struct members, because it had no type
196 .I time_t
197 yet.
198 .SH BUGS
199 A limitation of the Linux system call conventions on some architectures
200 (notably i386) means that on Linux 2.6 there is a small time window
201 (41 seconds) soon after boot when
202 .BR times ()
203 can return \-1, falsely indicating that an error occurred.
204 The same problem can occur when the return value wraps past
205 the maximum value that can be stored in
206 .BR clock_t .
207 .\" The problem is that a syscall return of -4095 to -1
208 .\" is interpreted by glibc as an error, and the wrapper converts
209 .\" the return value to -1.
210 .\" http://marc.info/?l=linux-kernel&m=119447727031225&w=2
211 .\" "compat_sys_times() bogus until jiffies >= 0"
212 .\" November 2007
213 .SH SEE ALSO
214 .BR time (1),
215 .BR getrusage (2),
216 .BR wait (2),
217 .BR clock (3),
218 .BR sysconf (3),
219 .BR time (7)