]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/times.2
mmap.2: Don't mark MAP_ANON as deprecated
[thirdparty/man-pages.git] / man2 / times.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
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>
c8f2dd47 30.\" Added note on nonstandard behavior when SIGCHLD is ignored.
cfea5132 31.\" Modified 2004-11-16, mtk, Noted that the nonconformance when
4c926acf 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
c8f2dd47 35.\" Added notes on nonstandard behavior: Linux allows 'buf' to
d603cc27 36.\" be NULL, but POSIX.1 doesn't specify this and it's nonportable.
fea681da 37.\"
4b8c67d9 38.TH TIMES 2 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da
MK
39.SH NAME
40times \- get process times
41.SH SYNOPSIS
42.B #include <sys/times.h>
68e4db0a 43.PP
fea681da
MK
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> :
57c3bde3 56.PP
088a639b 57.in +4n
57c3bde3 58.EX
fea681da 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 64};
57c3bde3 65.EE
d4c46761 66.in
dd3568a1 67.PP
fea681da
MK
68The
69.I tms_utime
70field contains the CPU time spent executing instructions
71of the calling process.
72The
73.I tms_stime
5bc53d81
MK
74field contains the CPU time spent executing inside the kernel
75while performing tasks on behalf of the calling process.
90c85e61 76.PP
fea681da
MK
77The
78.I tms_cutime
79field contains the sum of the
80.I tms_utime
81and
82.I tms_cutime
83values for all waited-for terminated children.
84The
85.I tms_cstime
86field contains the sum of the
87.I tms_stime
88and
89.I tms_cstime
90values for all waited-for terminated children.
dd3568a1 91.PP
fea681da 92Times for terminated children (and their descendants)
8c54c588 93are added in at the moment
fea681da
MK
94.BR wait (2)
95or
96.BR waitpid (2)
c13182ef
MK
97returns their process ID.
98In particular, times of grandchildren
fea681da 99that the children did not wait for are never seen.
dd3568a1 100.PP
fea681da 101All times reported are in clock ticks.
47297adb 102.SH RETURN VALUE
4c926acf 103.BR times ()
fea681da 104returns the number of clock ticks that have elapsed since
e263839c 105an arbitrary point in the past.
e263839c 106The return value may overflow the possible range of type
a5e0a0e4 107.IR clock_t .
e17aa487 108On error, \fI(clock_t)\ \-1\fP is returned, and
fea681da
MK
109.I errno
110is set appropriately.
962232bf
MK
111.SH ERRORS
112.TP
113.B EFAULT
114.I tms
115points outside the process's address space.
47297adb 116.SH CONFORMING TO
5788e863 117POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
fea681da 118.SH NOTES
f3fef736 119The number of clock ticks per second can be obtained using:
57c3bde3 120.PP
a6e2f128 121.in +4n
57c3bde3 122.EX
fea681da 123sysconf(_SC_CLK_TCK);
57c3bde3 124.EE
a6e2f128 125.in
f3fef736
MK
126.PP
127In POSIX.1-1996 the symbol \fBCLK_TCK\fP (defined in
fea681da 128.IR <time.h> )
c13182ef
MK
129is mentioned as obsolescent.
130It is obsolete now.
fea681da 131.PP
81841f39 132In Linux kernel versions before 2.6.9,
4c926acf
MK
133if the disposition of
134.B SIGCHLD
135is set to
665e7c79 136.BR SIG_IGN ,
fea681da
MK
137then the times of terminated children
138are automatically included in the
139.I tms_cstime
140and
141.I tms_cutime
33a0ccb2
MK
142fields, although POSIX.1-2001 says that this should happen
143only if the calling process
0bfa087b 144.BR wait (2)s
fea681da 145on its children.
cfea5132 146This nonconformance is rectified in Linux 2.6.9 and later.
fea681da
MK
147.\" See the description of times() in XSH, which says:
148.\" The times of a terminated child process are included... when wait()
704a18f0 149.\" or waitpid() returns the process ID of this terminated child.
efeece04 150.PP
b6ac5354
MK
151On Linux, the
152.I buf
153argument can be specified as NULL, with the result that
154.BR times ()
155just returns a function result.
d9bfdb9c 156However, POSIX does not specify this behavior, and most
008f1ecc 157other UNIX implementations require a non-NULL value for
b6ac5354 158.IR buf .
dd3568a1 159.PP
fea681da
MK
160Note that
161.BR clock (3)
5e27f149
MK
162also returns a value of type
163.IR clock_t ,
164but this value is measured in units of
165.BR CLOCKS_PER_SEC ,
166not the clock ticks used by
4ee6a53e 167.BR times ().
efeece04 168.PP
5e27f149
MK
169On Linux, the "arbitrary point in the past" from which the return value of
170.BR times ()
171is measured has varied across kernel versions.
329ad271 172On Linux 2.4 and earlier, this point is the moment the system was booted.
5e27f149 173Since Linux 2.6, this point is \fI(2^32/HZ) \- 300\fP
0e886e98 174seconds before system boot time.
008f1ecc 175This variability across kernel versions (and across UNIX implementations),
5e27f149
MK
176combined with the fact that the returned value may overflow the range of
177.IR clock_t ,
178means that a portable application would be wise to avoid using this value.
179To measure changes in elapsed time, use
ff393a5f 180.BR clock_gettime (2)
5e27f149
MK
181instead.
182.\" .PP
183.\" On older systems the number of clock ticks per second is given
184.\" by the variable HZ.
73d8cece 185.SS Historical
fea681da 186SVr1-3 returns
4c926acf 187.I long
fea681da 188and the struct members are of type
4c926acf 189.I time_t
be9634cf 190although they store clock ticks, not seconds since the Epoch.
c13182ef 191V7 used
4c926acf 192.I long
fea681da 193for the struct members, because it had no type
4c926acf 194.I time_t
fea681da 195yet.
5e27f149
MK
196.SH BUGS
197A limitation of the Linux system call conventions on some architectures
34ccb744 198(notably i386) means that on Linux 2.6 there is a small time window
5e27f149 199(41 seconds) soon after boot when
4ee6a53e 200.BR times ()
5e27f149 201can return \-1, falsely indicating that an error occurred.
24c1b109 202The same problem can occur when the return value wraps past
5e27f149 203the maximum value that can be stored in
20d58e69 204.BR clock_t .
5e27f149
MK
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
47297adb 211.SH SEE ALSO
fea681da
MK
212.BR time (1),
213.BR getrusage (2),
214.BR wait (2),
215.BR clock (3),
eafd5ce1
MK
216.BR sysconf (3),
217.BR time (7)