1CLOCK(3)                   Linux Programmer's Manual                  CLOCK(3)
2
3
4

NAME

6       clock - determine processor time
7

SYNOPSIS

9       #include <time.h>
10
11       clock_t clock(void);
12

DESCRIPTION

14       The clock() function returns an approximation of processor time used by
15       the program.
16

RETURN VALUE

18       The value returned is the CPU time used so far as a clock_t; to get the
19       number  of  seconds  used,  divide by CLOCKS_PER_SEC.  If the processor
20       time used is not available or its  value  cannot  be  represented,  the
21       function returns the value (clock_t) -1.
22

ATTRIBUTES

24       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
25       tributes(7).
26
27       ┌────────────────────────────────────────────┬───────────────┬─────────┐
28Interface                                   Attribute     Value   
29       ├────────────────────────────────────────────┼───────────────┼─────────┤
30clock()                                     │ Thread safety │ MT-Safe │
31       └────────────────────────────────────────────┴───────────────┴─────────┘
32

CONFORMING TO

34       POSIX.1-2001, POSIX.1-2008, C89, C99.  XSI requires that CLOCKS_PER_SEC
35       equals 1000000 independent of the actual resolution.
36

NOTES

38       The C standard allows for arbitrary values at the start of the program;
39       subtract the value returned from a call to clock() at the start of  the
40       program to get maximum portability.
41
42       Note  that  the  time  can  wrap  around.   On  a  32-bit  system where
43       CLOCKS_PER_SEC equals 1000000 this function will return the same  value
44       approximately every 72 minutes.
45
46       On  several  other  implementations, the value returned by clock() also
47       includes the times of any children whose status has been collected  via
48       wait(2)  (or another wait-type call).  Linux does not include the times
49       of waited-for children in the value returned by clock().  The  times(2)
50       function,  which  explicitly  returns  (separate) information about the
51       caller and its children, may be preferable.
52
53       In glibc 2.17 and earlier, clock() was implemented on top of  times(2).
54       For  improved  accuracy,  since glibc 2.18, it is implemented on top of
55       clock_gettime(2) (using the CLOCK_PROCESS_CPUTIME_ID clock).
56

SEE ALSO

58       clock_gettime(2), getrusage(2), times(2)
59

COLOPHON

61       This page is part of release 5.12 of the Linux  man-pages  project.   A
62       description  of  the project, information about reporting bugs, and the
63       latest    version    of    this    page,    can     be     found     at
64       https://www.kernel.org/doc/man-pages/.
65
66
67
68GNU                               2021-03-22                          CLOCK(3)
Impressum