OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / man2 / times.2
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)
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 2008-06-25 "Linux" "Linux Programmer's Manual"
39 .SH NAME
40 times \- 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 ()
47 stores the current process times in the
48 .I "struct tms"
49 that
50 .I buf
51 points to.
52 The
53 .I struct tms
54 is as defined in
55 .IR <sys/times.h> :
56 .sp
57 .in +4n
58 .nf
59 struct 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
68 The
69 .I tms_utime
70 field contains the CPU time spent executing instructions
71 of the calling process.
72 The
73 .I tms_stime
74 field contains the CPU time spent in the system while
75 executing tasks on behalf of the calling process.
76 The
77 .I tms_cutime
78 field contains the sum of the
79 .I tms_utime
80 and
81 .I tms_cutime
82 values for all waited-for terminated children.
83 The
84 .I tms_cstime
85 field contains the sum of the
86 .I tms_stime
87 and
88 .I tms_cstime
89 values for all waited-for terminated children.
90 .LP
91 Times for terminated children (and their descendants)
92 are added in at the moment
93 .BR wait (2)
94 or
95 .BR waitpid (2)
96 returns their process ID.
97 In particular, times of grandchildren
98 that the children did not wait for are never seen.
99 .LP
100 All times reported are in clock ticks.
101 .SH "RETURN VALUE"
102 .BR times ()
103 returns the number of clock ticks that have elapsed since
104 an arbitrary point in the past.
105 The return value may overflow the possible range of type
106 .IR clock_t .
107 On error, \fI(clock_t)\ \-1\fP is returned, and
108 .I errno
109 is set appropriately.
110 .\" The only possible error is EFAULT.
111 .SH "CONFORMING TO"
112 SVr4, 4.3BSD, POSIX.1-2001.
113 .SH NOTES
114 The number of clock ticks per second can be obtained using:
115 .in +4n
116
117 sysconf(_SC_CLK_TCK);
118 .in
119 .PP
120 In POSIX.1-1996 the symbol \fBCLK_TCK\fP (defined in
121 .IR <time.h> )
122 is mentioned as obsolescent.
123 It is obsolete now.
124 .PP
125 In Linux kernel versions before 2.6.9,
126 if the disposition of
127 .B SIGCHLD
128 is set to
129 .B SIG_IGN
130 then the times of terminated children
131 are automatically included in the
132 .I tms_cstime
133 and
134 .I tms_cutime
135 fields, although POSIX.1-2001 says that this should only happen
136 if the calling process
137 .BR wait (2)s
138 on its children.
139 This nonconformance is rectified in Linux 2.6.9 and later.
140 .\" See the description of times() in XSH, which says:
141 .\"     The times of a terminated child process are included... when wait()
142 .\"     or waitpid() returns the process ID of this terminated child.
143
144 On Linux, the
145 .I buf
146 argument can be specified as NULL, with the result that
147 .BR times ()
148 just returns a function result.
149 However, POSIX does not specify this behavior, and most
150 other UNIX implementations require a non-NULL value for
151 .IR buf .
152 .LP
153 Note that
154 .BR clock (3)
155 also returns a value of type
156 .IR clock_t ,
157 but this value is measured in units of
158 .BR CLOCKS_PER_SEC ,
159 not the clock ticks used by
160 .BR times ().
161
162 On Linux, the "arbitrary point in the past" from which the return value of
163 .BR times ()
164 is measured has varied across kernel versions.
165 On Linux 2.4 and earlier this point is the moment the system was booted.
166 Since Linux 2.6, this point is \fI(2^32/HZ) \- 300\fP
167 (i.e., about 429 million) seconds before system boot time.
168 This variability across kernel versions (and across UNIX implementations),
169 combined with the fact that the returned value may overflow the range of
170 .IR clock_t ,
171 means that a portable application would be wise to avoid using this value.
172 To measure changes in elapsed time, use
173 .BR gettimeofday (2)
174 instead.
175 .\" .PP
176 .\" On older systems the number of clock ticks per second is given
177 .\" by the variable HZ.
178 .SS "Historical"
179 SVr1-3 returns
180 .I long
181 and the struct members are of type
182 .I time_t
183 although they store clock ticks, not seconds since the Epoch.
184 V7 used
185 .I long
186 for the struct members, because it had no type
187 .I time_t
188 yet.
189 .SH BUGS
190 A limitation of the Linux system call conventions on some architectures
191 (notably i386) means that on Linux 2.6 there is a small time window
192 (41 seconds) soon after boot when
193 .BR times ()
194 can return \-1, falsely indicating that an error occurred.
195 The same problem can occur when the return value wraps passed
196 the 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
204 .SH "SEE ALSO"
205 .BR time (1),
206 .BR getrusage (2),
207 .BR wait (2),
208 .BR clock (3),
209 .BR sysconf (3),
210 .BR time (7)