]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/times.2
Noted the PID caching behaviour of NPTL's getpid() wrapper under BUGS.
[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.
13.\"
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.
21.\"
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)
305a0578 29.\" Modified 13 Jun 02, Michael Kerrisk <mtk-manpages@gmx.net>
fea681da 30.\" Added note on non-standard behaviour 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
fea681da
MK
34.\"
35.TH TIMES 2 2002-06-14 "Linux" "Linux Programmer's Manual"
36.SH NAME
37times \- get process times
38.SH SYNOPSIS
39.B #include <sys/times.h>
40.sp
41.BI "clock_t times(struct tms *" buf );
42.SH DESCRIPTION
fea681da 43.BR times ()
4c926acf
MK
44stores the current process times in the
45.I "struct tms"
fea681da
MK
46that
47.IR buf
48points to.
49The
50.I struct tms
51is as defined in
52.IR <sys/times.h> :
53.sp
54.nf
55struct tms {
56.RS
57clock_t tms_utime; /* user time */
58clock_t tms_stime; /* system time */
59clock_t tms_cutime; /* user time of children */
60clock_t tms_cstime; /* system time of children */
61.RE
62};
63.fi
64.LP
65The
66.I tms_utime
67field contains the CPU time spent executing instructions
68of the calling process.
69The
70.I tms_stime
71field contains the CPU time spent in the system while
72executing tasks on behalf of the calling process.
73The
74.I tms_cutime
75field contains the sum of the
76.I tms_utime
77and
78.I tms_cutime
79values for all waited-for terminated children.
80The
81.I tms_cstime
82field contains the sum of the
83.I tms_stime
84and
85.I tms_cstime
86values for all waited-for terminated children.
87.LP
88Times for terminated children (and their descendants)
89is added in at the moment
90.BR wait (2)
91or
92.BR waitpid (2)
93returns their process ID. In particular, times of grandchildren
94that the children did not wait for are never seen.
95.LP
96All times reported are in clock ticks.
97.SH "RETURN VALUE"
4c926acf 98.BR times ()
fea681da 99returns the number of clock ticks that have elapsed since
e263839c
MK
100an arbitrary point in the past.
101For Linux 2.4 and earlier this point is the moment the system was booted.
540036b2
MK
102Since Linux 2.6, this point is \fI(2^32/HZ) - 300\fP
103(i.e., about 429 million) seconds before system boot time.
e263839c 104The return value may overflow the possible range of type
4c926acf
MK
105.I clock_t.
106On error, \fI(clock_t) \-1\fP is returned, and
fea681da
MK
107.I errno
108is set appropriately.
109.SH NOTES
110The number of clock ticks per second can be obtained using
111.RS
112sysconf(_SC_CLK_TCK);
113.RE
114In POSIX-1996 the symbol CLK_TCK (defined in
115.IR <time.h> )
116is mentioned as obsolescent. It is obsolete now.
117.PP
81841f39 118In Linux kernel versions before 2.6.9,
4c926acf
MK
119if the disposition of
120.B SIGCHLD
121is set to
fea681da
MK
122.B SIG_IGN
123then the times of terminated children
124are automatically included in the
125.I tms_cstime
126and
127.I tms_cutime
128fields, although POSIX 1003.1-2001 says that this should only happen
129if the calling process
130.BR wait ()s
131on its children.
81841f39 132This non-conformance is rectified in Linux 2.6.9 and later.
fea681da
MK
133.\" See the description of times() in XSH, which says:
134.\" The times of a terminated child process are included... when wait()
135.\" or waitpid() returns the process ID of this termianted child.
136.LP
137Note that
138.BR clock (3)
4c926acf
MK
139returns values of type
140.I clock_t
141that are not measured in clock ticks
142but in
143.BR CLOCKS_PER_SEC .
fea681da
MK
144.SH "CONFORMING TO"
145SVr4, SVID, POSIX, X/OPEN, BSD 4.3
146.SH "HISTORICAL NOTES"
147SVr1-3 returns
4c926acf 148.I long
fea681da 149and the struct members are of type
4c926acf 150.I time_t
fea681da 151although they store clock ticks, not seconds since the epoch. V7 used
4c926acf 152.I long
fea681da 153for the struct members, because it had no type
4c926acf 154.I time_t
fea681da
MK
155yet.
156.PP
157On older systems the number of clock ticks per second is given
158by the variable HZ.
159.SH "SEE ALSO"
160.BR time (1),
161.BR getrusage (2),
162.BR wait (2),
163.BR clock (3),
164.BR sysconf (3)