]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/clock.3
encrypt.3: srcfix: rewrap source lines
[thirdparty/man-pages.git] / man3 / clock.3
CommitLineData
bf5a7247 1.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
fea681da 2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
c08df37a 24.\"
fea681da 25.\" Modified Sat Jul 24 21:27:01 1993 by Rik Faith (faith@cs.unc.edu)
c11b1abf 26.\" Modified 14 Jun 2002, Michael Kerrisk <mtk.manpages@gmail.com>
008f1ecc 27.\" Added notes on differences from other UNIX systems with respect to
fea681da 28.\" waited-for children.
4b8c67d9 29.TH CLOCK 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da 30.SH NAME
f68512e9 31clock \- determine processor time
fea681da
MK
32.SH SYNOPSIS
33.nf
34.B #include <time.h>
68e4db0a 35.PP
fea681da
MK
36.B clock_t clock(void);
37.fi
38.SH DESCRIPTION
39The
63aa9df0 40.BR clock ()
fea681da 41function returns an approximation of processor time used by the program.
47297adb 42.SH RETURN VALUE
fea681da 43The value returned is the CPU time used so far as a
66ee0c7e 44.IR clock_t ;
fea681da
MK
45to get the number of seconds used, divide by
46.BR CLOCKS_PER_SEC .
47If the processor time used is not available or its value cannot
66ee0c7e 48be represented, the function returns the value
009df872 49.IR (clock_t)\ \-1 .
11cf4a69
MS
50.SH ATTRIBUTES
51For an explanation of the terms used in this section, see
52.BR attributes (7).
53.TS
54allbox;
55lb lb lb
56l l l.
57Interface Attribute Value
58T{
59.BR clock ()
60T} Thread safety MT-Safe
61.TE
847e0d88 62.sp 1
47297adb 63.SH CONFORMING TO
a42f92e1 64POSIX.1-2001, POSIX.1-2008, C89, C99.
504b1c79 65XSI requires that
e5056894
MK
66.B CLOCKS_PER_SEC
67equals 1000000 independent
fea681da
MK
68of the actual resolution.
69.SH NOTES
70The C standard allows for arbitrary values at the start of the program;
71subtract the value returned from a call to
63aa9df0 72.BR clock ()
fea681da
MK
73at the start of the program to get maximum portability.
74.PP
c13182ef 75Note that the time can wrap around.
d4725a0e 76On a 32-bit system where
e5056894
MK
77.B CLOCKS_PER_SEC
78equals 1000000 this function will return the same
fea681da
MK
79value approximately every 72 minutes.
80.PP
81On several other implementations,
c13182ef 82the value returned by
fea681da
MK
83.BR clock ()
84also includes the times of any children whose status has been
85collected via
fb186734 86.BR wait (2)
fea681da
MK
87(or another wait-type call).
88Linux does not include the times of waited-for children in the
89value returned by
90.BR clock ().
d9bfdb9c 91.\" I have seen this behavior on Irix 6.3, and the OSF/1, HP/UX, and
fea681da 92.\" Solaris manual pages say that clock() also does this on those systems.
68e1685c 93.\" POSIX.1-2001 doesn't explicitly allow this, nor is there an
fea681da
MK
94.\" explicit prohibition. -- MTK
95The
fb186734 96.BR times (2)
c13182ef 97function, which explicitly returns (separate) information about the
fea681da 98caller and its children, may be preferable.
847e0d88 99.PP
fa182455
MK
100In glibc 2.17 and earlier,
101.BR clock ()
102was implemented on top of
103.BR times (2).
f35f30b8 104For improved accuracy,
fa182455
MK
105since glibc 2.18, it is implemented on top of
106.BR clock_gettime (2)
107(using the
108.BR CLOCK_PROCESS_CPUTIME_ID
109clock).
47297adb 110.SH SEE ALSO
0eb44391 111.BR clock_gettime (2),
fea681da 112.BR getrusage (2),
0eb44391 113.BR times (2)