]> git.ipfire.org Git - thirdparty/man-pages.git/blame_incremental - man2/times.2
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man2 / times.2
... / ...
CommitLineData
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 2012-10-22 "Linux" "Linux Programmer's Manual"
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
46.BR times ()
47stores the current process times in the
48.I "struct tms"
49that
50.I buf
51points to.
52The
53.I struct tms
54is as defined in
55.IR <sys/times.h> :
56.sp
57.in +4n
58.nf
59struct 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.fi
66.in
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)
92are added in at the moment
93.BR wait (2)
94or
95.BR waitpid (2)
96returns their process ID.
97In particular, times of grandchildren
98that the children did not wait for are never seen.
99.LP
100All times reported are in clock ticks.
101.SH RETURN VALUE
102.BR times ()
103returns the number of clock ticks that have elapsed since
104an arbitrary point in the past.
105The return value may overflow the possible range of type
106.IR clock_t .
107On error, \fI(clock_t)\ \-1\fP is returned, and
108.I errno
109is set appropriately.
110.SH ERRORS
111.TP
112.B EFAULT
113.I tms
114points outside the process's address space.
115.SH CONFORMING TO
116SVr4, 4.3BSD, POSIX.1-2001.
117.SH NOTES
118The number of clock ticks per second can be obtained using:
119.in +4n
120
121sysconf(_SC_CLK_TCK);
122.in
123.PP
124In POSIX.1-1996 the symbol \fBCLK_TCK\fP (defined in
125.IR <time.h> )
126is mentioned as obsolescent.
127It is obsolete now.
128.PP
129In Linux kernel versions before 2.6.9,
130if the disposition of
131.B SIGCHLD
132is set to
133.B SIG_IGN
134then the times of terminated children
135are automatically included in the
136.I tms_cstime
137and
138.I tms_cutime
139fields, although POSIX.1-2001 says that this should only happen
140if the calling process
141.BR wait (2)s
142on its children.
143This nonconformance is rectified in Linux 2.6.9 and later.
144.\" See the description of times() in XSH, which says:
145.\" The times of a terminated child process are included... when wait()
146.\" or waitpid() returns the process ID of this terminated child.
147
148On Linux, the
149.I buf
150argument can be specified as NULL, with the result that
151.BR times ()
152just returns a function result.
153However, POSIX does not specify this behavior, and most
154other UNIX implementations require a non-NULL value for
155.IR buf .
156.LP
157Note that
158.BR clock (3)
159also returns a value of type
160.IR clock_t ,
161but this value is measured in units of
162.BR CLOCKS_PER_SEC ,
163not the clock ticks used by
164.BR times ().
165
166On Linux, the "arbitrary point in the past" from which the return value of
167.BR times ()
168is measured has varied across kernel versions.
169On Linux 2.4 and earlier this point is the moment the system was booted.
170Since Linux 2.6, this point is \fI(2^32/HZ) \- 300\fP
171(i.e., about 429 million) seconds before system boot time.
172This variability across kernel versions (and across UNIX implementations),
173combined with the fact that the returned value may overflow the range of
174.IR clock_t ,
175means that a portable application would be wise to avoid using this value.
176To measure changes in elapsed time, use
177.BR clock_gettime (2)
178instead.
179.\" .PP
180.\" On older systems the number of clock ticks per second is given
181.\" by the variable HZ.
182.SS Historical
183SVr1-3 returns
184.I long
185and the struct members are of type
186.I time_t
187although they store clock ticks, not seconds since the Epoch.
188V7 used
189.I long
190for the struct members, because it had no type
191.I time_t
192yet.
193.SH BUGS
194A limitation of the Linux system call conventions on some architectures
195(notably i386) means that on Linux 2.6 there is a small time window
196(41 seconds) soon after boot when
197.BR times ()
198can return \-1, falsely indicating that an error occurred.
199The same problem can occur when the return value wraps passed
200the maximum value that can be stored in
201.BR clock_t .
202.\" The problem is that a syscall return of -4095 to -1
203.\" is interpreted by glibc as an error, and the wrapper converts
204.\" the return value to -1.
205.\" http://marc.info/?l=linux-kernel&m=119447727031225&w=2
206.\" "compat_sys_times() bogus until jiffies >= 0"
207.\" November 2007
208.SH SEE ALSO
209.BR time (1),
210.BR getrusage (2),
211.BR wait (2),
212.BR clock (3),
213.BR sysconf (3),
214.BR time (7)