]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/clock.3
ffix
[thirdparty/man-pages.git] / man3 / clock.3
1 .\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\" Modified Sat Jul 24 21:27:01 1993 by Rik Faith (faith@cs.unc.edu)
24 .\" Modified 14 Jun 2002, Michael Kerrisk <mtk-manpages@gmx.net>
25 .\" Added notes on differences from other Unix systems with respect to
26 .\" waited-for children.
27 .TH CLOCK 3 2002-06-14 "GNU" "Linux Programmer's Manual"
28 .SH NAME
29 clock \- Determine processor time
30 .SH SYNOPSIS
31 .nf
32 .B #include <time.h>
33 .sp
34 .B clock_t clock(void);
35 .fi
36 .SH DESCRIPTION
37 The
38 .BR clock ()
39 function returns an approximation of processor time used by the program.
40 .SH "RETURN VALUE"
41 The value returned is the CPU time used so far as a
42 .IR clock_t ;
43 to get the number of seconds used, divide by
44 .BR CLOCKS_PER_SEC .
45 If the processor time used is not available or its value cannot
46 be represented, the function returns the value
47 .BR (clock_t)\-1 .
48 .SH "CONFORMING TO"
49 C89, C99, POSIX.1-2001.
50 POSIX requires that CLOCKS_PER_SEC equals 1000000 independent
51 of the actual resolution.
52 .SH NOTES
53 The C standard allows for arbitrary values at the start of the program;
54 subtract the value returned from a call to
55 .BR clock ()
56 at the start of the program to get maximum portability.
57 .PP
58 Note that the time can wrap around.
59 On a 32bit system where
60 CLOCKS_PER_SEC equals 1000000 this function will return the same
61 value approximately every 72 minutes.
62 .PP
63 On several other implementations,
64 the value returned by
65 .BR clock ()
66 also includes the times of any children whose status has been
67 collected via
68 .BR wait (2)
69 (or another wait-type call).
70 Linux does not include the times of waited-for children in the
71 value returned by
72 .BR clock ().
73 .\" I have seen this behavior on Irix 6.3, and the OSF/1, HP/UX, and
74 .\" Solaris manual pages say that clock() also does this on those systems.
75 .\" POSIX.1-2001 doesn't explicitly allow this, nor is there an
76 .\" explicit prohibition. -- MTK
77 The
78 .BR times (2)
79 function, which explicitly returns (separate) information about the
80 caller and its children, may be preferable.
81 .SH "SEE ALSO"
82 .BR getrusage (2),
83 .BR times (2)