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