DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

clock(S)


clock -- report CPU time used

Syntax

cc . . . -lc

long clock ()

Description

The clock function returns the amount of CPU time (in microseconds) used since the first call to clock. 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 wait(S), pclose(S), or system(S).

The resolution of the time values returned is 10,000 microseconds (10 milliseconds), corresponding to the value of HZ within the kernel..

Notes

The value returned wraps around after accumulating 2147 seconds of CPU time (about 36 minutes). Code that compares old and new clock values must be written to be accurate across these wraps. For example, to determine whether or not MAX_TIME has passed since start_time:
   int start_time
   

if (clock - start_time >= MAX_TIME)

This subtraction works whether clock( ) values are negative or positive. start_time must be declared as a signed integer.

Avoid using constructions such as the following:

   if (clock >= (start_time + MAX_TIME))  /* INCORRECT use of clock */
This fails if (start_time + MAX_TIME) is positive while clock( ) has wrapped and is negative.

See also

clock(HW), popen(S), system(S), times(S), wait(S)

Standards conformance

clock is conformant with:

X/Open Portability Guide, Issue 3, 1989 .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003