]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/clock.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / clock.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" Modified Sat Jul 24 21:27:01 1993 by Rik Faith (faith@cs.unc.edu)
6 .\" Modified 14 Jun 2002, Michael Kerrisk <mtk.manpages@gmail.com>
7 .\" Added notes on differences from other UNIX systems with respect to
8 .\" waited-for children.
9 .TH clock 3 (date) "Linux man-pages (unreleased)"
10 .SH NAME
11 clock \- determine processor time
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <time.h>
18 .PP
19 .B clock_t clock(void);
20 .fi
21 .SH DESCRIPTION
22 The
23 .BR clock ()
24 function returns an approximation of processor time used by the program.
25 .SH RETURN VALUE
26 The value returned is the CPU time used so far as a
27 .IR clock_t ;
28 to get the number of seconds used, divide by
29 .BR CLOCKS_PER_SEC .
30 If the processor time used is not available or its value cannot
31 be represented, the function returns the value
32 .IR (clock_t)\ \-1 .
33 .SH ATTRIBUTES
34 For an explanation of the terms used in this section, see
35 .BR attributes (7).
36 .ad l
37 .nh
38 .TS
39 allbox;
40 lbx lb lb
41 l l l.
42 Interface Attribute Value
43 T{
44 .BR clock ()
45 T} Thread safety MT-Safe
46 .TE
47 .hy
48 .ad
49 .sp 1
50 .SH STANDARDS
51 POSIX.1-2001, POSIX.1-2008, C89, C99.
52 XSI requires that
53 .B CLOCKS_PER_SEC
54 equals 1000000 independent
55 of the actual resolution.
56 .SH NOTES
57 The C standard allows for arbitrary values at the start of the program;
58 subtract the value returned from a call to
59 .BR clock ()
60 at the start of the program to get maximum portability.
61 .PP
62 Note that the time can wrap around.
63 On a 32-bit system where
64 .B CLOCKS_PER_SEC
65 equals 1000000 this function will return the same
66 value approximately every 72 minutes.
67 .PP
68 On several other implementations,
69 the value returned by
70 .BR clock ()
71 also includes the times of any children whose status has been
72 collected via
73 .BR wait (2)
74 (or another wait-type call).
75 Linux does not include the times of waited-for children in the
76 value returned by
77 .BR clock ().
78 .\" I have seen this behavior on Irix 6.3, and the OSF/1, HP/UX, and
79 .\" Solaris manual pages say that clock() also does this on those systems.
80 .\" POSIX.1-2001 doesn't explicitly allow this, nor is there an
81 .\" explicit prohibition. -- MTK
82 The
83 .BR times (2)
84 function, which explicitly returns (separate) information about the
85 caller and its children, may be preferable.
86 .PP
87 In glibc 2.17 and earlier,
88 .BR clock ()
89 was implemented on top of
90 .BR times (2).
91 For improved accuracy,
92 since glibc 2.18, it is implemented on top of
93 .BR clock_gettime (2)
94 (using the
95 .B CLOCK_PROCESS_CPUTIME_ID
96 clock).
97 .SH SEE ALSO
98 .BR clock_gettime (2),
99 .BR getrusage (2),
100 .BR times (2)