]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/times.2
Starte of 2.51
[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)
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
b6ac5354
MK
34.\" 2005-04-13, mtk
35.\" Added notes on non-standard behaviour: Linux allows 'buf' to
36.\" be NULL, but POSIX.1 doesn't specify this and it's non-portable.
fea681da
MK
37.\"
38.TH TIMES 2 2002-06-14 "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
fea681da 46.BR times ()
4c926acf
MK
47stores the current process times in the
48.I "struct tms"
fea681da
MK
49that
50.IR buf
51points to.
52The
53.I struct tms
54is as defined in
55.IR <sys/times.h> :
56.sp
57.nf
58struct tms {
59.RS
60clock_t tms_utime; /* user time */
61clock_t tms_stime; /* system time */
62clock_t tms_cutime; /* user time of children */
63clock_t tms_cstime; /* system time of children */
64.RE
65};
66.fi
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
MK
104an arbitrary point in the past.
105For Linux 2.4 and earlier this point is the moment the system was booted.
e9496f74 106Since Linux 2.6, this point is \fI(2^32/HZ) \- 300\fP
540036b2 107(i.e., about 429 million) seconds before system boot time.
e263839c 108The return value may overflow the possible range of type
a5e0a0e4 109.IR clock_t .
4c926acf 110On error, \fI(clock_t) \-1\fP is returned, and
fea681da
MK
111.I errno
112is set appropriately.
113.SH NOTES
114The number of clock ticks per second can be obtained using
115.RS
116sysconf(_SC_CLK_TCK);
117.RE
118In POSIX-1996 the symbol CLK_TCK (defined in
119.IR <time.h> )
c13182ef
MK
120is mentioned as obsolescent.
121It is obsolete now.
fea681da 122.PP
81841f39 123In Linux kernel versions before 2.6.9,
4c926acf
MK
124if the disposition of
125.B SIGCHLD
126is set to
fea681da
MK
127.B SIG_IGN
128then the times of terminated children
129are automatically included in the
130.I tms_cstime
131and
132.I tms_cutime
97c1eac8 133fields, although POSIX.1-2001 says that this should only happen
fea681da
MK
134if the calling process
135.BR wait ()s
136on its children.
81841f39 137This non-conformance is rectified in Linux 2.6.9 and later.
fea681da
MK
138.\" See the description of times() in XSH, which says:
139.\" The times of a terminated child process are included... when wait()
704a18f0 140.\" or waitpid() returns the process ID of this terminated child.
b6ac5354
MK
141
142On Linux, the
143.I buf
144argument can be specified as NULL, with the result that
145.BR times ()
146just returns a function result.
147However, POSIX does not specify this behaviour, and most
148other Unix implementations require a non-NULL value for
149.IR buf .
fea681da
MK
150.LP
151Note that
152.BR clock (3)
4c926acf
MK
153returns values of type
154.I clock_t
155that are not measured in clock ticks
156but in
157.BR CLOCKS_PER_SEC .
fea681da 158.SH "CONFORMING TO"
97c1eac8 159SVr4, 4.3BSD, POSIX.1-2001.
fea681da
MK
160.SH "HISTORICAL NOTES"
161SVr1-3 returns
4c926acf 162.I long
fea681da 163and the struct members are of type
4c926acf 164.I time_t
c13182ef
MK
165although they store clock ticks, not seconds since the epoch.
166V7 used
4c926acf 167.I long
fea681da 168for the struct members, because it had no type
4c926acf 169.I time_t
fea681da
MK
170yet.
171.PP
172On older systems the number of clock ticks per second is given
173by the variable HZ.
174.SH "SEE ALSO"
175.BR time (1),
176.BR getrusage (2),
177.BR wait (2),
178.BR clock (3),
eafd5ce1
MK
179.BR sysconf (3),
180.BR time (7)