CLOCK(3) Linux Programmer's Manual CLOCK(3)NAME
clock - Determine processor time
SYNOPSIS
#include <time.h>
clock_t clock(void);
DESCRIPTION
The clock() function returns an approximation of processor time used by the program.
RETURN VALUE
The value returned is the CPU time used so far as a clock_t; to get the number of seconds used, divide by CLOCKS_PER_SEC. If the processor
time used is not available or its value cannot be represented, the function returns the value (clock_t)-1.
CONFORMING TO
ANSI C. POSIX requires that CLOCKS_PER_SEC equals 1000000 independent of the actual resolution.
NOTES
The C standard allows for arbitrary values at the start of the program; subtract the value returned from a call to clock() at the start of
the program to get maximum portability.
Note that the time can wrap around. On a 32bit system where CLOCKS_PER_SEC equals 1000000 this function will return the same value approx-
imately every 72 minutes.
On several other implementations, the value returned by clock() also includes the times of any children whose status has been collected via
wait() (or another wait-type call). Linux does not include the times of waited-for children in the value returned by clock(). The times()
function, which explicitly returns (separate) information about the caller and its children, may be preferable.
SEE ALSO getrusage(2), times(2)GNU 2002-06-14 CLOCK(3)
Check Out this Related Man Page
clock(3C) Standard C Library Functions clock(3C)NAME
clock - report CPU time used
SYNOPSIS
#include <time.h>
clock_t clock(void);
DESCRIPTION
The clock() function returns the amount of CPU time (in microseconds) used since the first call to clock() in the calling process. The time
reported is the sum of the user and system times of the calling process and its terminated child processes for which it has executed the
wait(3C) function, the pclose(3C) function, or the system(3C) function.
RETURN VALUES
Dividing the value returned by clock() by the constant CLOCKS_PER_SEC, defined in the <time.h> header, will give the time in seconds. If
the process time used is not available or cannot be represented, clock returns the value (clock_t) -1.
USAGE
The value returned by clock() is defined in microseconds for compatibility with systems that have CPU clocks with much higher resolution.
Because of this, the value returned will wrap around after accumulating only 2147 seconds of CPU time (about 36 minutes).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO times(2), popen(3C), system(3C), wait(3C), attributes(5), standards(5)SunOS 5.11 24 Jul 2002 clock(3C)
I thought a program's elapsed time, some program language call it real time, should be the time of a program from start to finish. And it should be equal or longer than CPU time. This is true for the most of the cases. However, I do see some of my programs CPU time is longer than Elapsed time. ... (1 Reply)
Hello,
I am using C on a Centos box with gcc as the compiler.
I want a function to do something, them make an http request to some server (most probably using curl but suggestions are welcome) and return right away without waiting for the server's answer on that request.
What should I use... (8 Replies)
We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call.
I've tried something like this:
#!/bin/sh
for i in $*;do
if !
then
echo $i is not a C file.
else echo $i... (0 Replies)