OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / clock.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified Sat Jul 24 21:27:01 1993 by Rik Faith (faith@cs.unc.edu)
26 .\" Modified 14 Jun 2002, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\"     Added notes on differences from other UNIX systems with respect to
28 .\"     waited-for children.
29 .TH CLOCK 3  2014-09-21 "GNU" "Linux Programmer's Manual"
30 .SH NAME
31 clock \- determine processor time
32 .SH SYNOPSIS
33 .nf
34 .B #include <time.h>
35 .sp
36 .B clock_t clock(void);
37 .fi
38 .SH DESCRIPTION
39 The
40 .BR clock ()
41 function returns an approximation of processor time used by the program.
42 .SH RETURN VALUE
43 The value returned is the CPU time used so far as a
44 .IR clock_t ;
45 to get the number of seconds used, divide by
46 .BR CLOCKS_PER_SEC .
47 If the processor time used is not available or its value cannot
48 be represented, the function returns the value
49 .IR (clock_t)\ \-1 .
50 .SH CONFORMING TO
51 C89, C99, POSIX.1-2001.
52 POSIX 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
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 .BR CLOCK_PROCESS_CPUTIME_ID
96 clock).
97 .SH SEE ALSO
98 .BR clock_gettime (2),
99 .BR getrusage (2),
100 .BR times (2)
101 .SH COLOPHON
102 This page is part of release 3.79 of the Linux
103 .I man-pages
104 project.
105 A description of the project,
106 information about reporting bugs,
107 and the latest version of this page,
108 can be found at
109 \%http://www.kernel.org/doc/man\-pages/.