165 lines
3.9 KiB
HTML
165 lines
3.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of CLOCK</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>CLOCK</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
clock - determine processor time
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/time.h">time.h</A>></B>
|
|
|
|
<B>clock_t clock(void);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>clock</B>()
|
|
|
|
function returns an approximation of processor time used by the program.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The value returned is the CPU time used so far as a
|
|
<I>clock_t</I>;
|
|
|
|
to get the number of seconds used, divide by
|
|
<B>CLOCKS_PER_SEC</B>.
|
|
|
|
If the processor time used is not available or its value cannot
|
|
be represented, the function returns the value
|
|
<I>(clock_t) -1</I>.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>clock</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, C89, C99.
|
|
XSI requires that
|
|
<B>CLOCKS_PER_SEC</B>
|
|
|
|
equals 1000000 independent
|
|
of the actual resolution.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The C standard allows for arbitrary values at the start of the program;
|
|
subtract the value returned from a call to
|
|
<B>clock</B>()
|
|
|
|
at the start of the program to get maximum portability.
|
|
<P>
|
|
|
|
Note that the time can wrap around.
|
|
On a 32-bit system where
|
|
<B>CLOCKS_PER_SEC</B>
|
|
|
|
equals 1000000 this function will return the same
|
|
value approximately every 72 minutes.
|
|
<P>
|
|
|
|
On several other implementations,
|
|
the value returned by
|
|
<B>clock</B>()
|
|
|
|
also includes the times of any children whose status has been
|
|
collected via
|
|
<B><A HREF="/cgi-bin/man/man2html?2+wait">wait</A></B>(2)
|
|
|
|
(or another wait-type call).
|
|
Linux does not include the times of waited-for children in the
|
|
value returned by
|
|
<B>clock</B>().
|
|
|
|
|
|
|
|
|
|
|
|
The
|
|
<B><A HREF="/cgi-bin/man/man2html?2+times">times</A></B>(2)
|
|
|
|
function, which explicitly returns (separate) information about the
|
|
caller and its children, may be preferable.
|
|
<P>
|
|
|
|
In glibc 2.17 and earlier,
|
|
<B>clock</B>()
|
|
|
|
was implemented on top of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+times">times</A></B>(2).
|
|
|
|
For improved accuracy,
|
|
since glibc 2.18, it is implemented on top of
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2)
|
|
|
|
(using the
|
|
<B>CLOCK_PROCESS_CPUTIME_ID</B>
|
|
|
|
clock).
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getrusage">getrusage</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+times">times</A></B>(2)
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">ATTRIBUTES</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:37 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|