[Previous]
[Contents]
[Next]

clock_getres()

get the resolution of the clock

Synopsis:

#include <time.h>
int clock_getres( clockid_t clock_id, 
                  struct timespec *res );

Description:

The clock_getres() function gets the resolution of the clock specified by clock_id and puts it into the buffer pointed to by res. The only supported clock ID is CLOCK_REALTIME.

The res parameter points to a structure containing at least the following members:

time_t tv_sec
This field is zero.
time_t tv_nsec
the resolution of the clock, in nanoseconds

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EINVAL
The clock_id is not CLOCK_REALTIME.

Examples:

/*
 * This program prints out the clock resolution.
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void )
  {
    struct timespec res;

    if ( clock_getres( CLOCK_REALTIME, &res) == -1 ) {
      perror( "clock get resolution" );
      exit( EXIT_FAILURE );
    }
    printf( "Resolution is %ld micro seconds.\n",
          res.tv_nsec / 1000 );
    return( EXIT_SUCCESS );
  }

Classification:

POSIX 1003.4

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

clock_gettime(), clock_setres(), clock_settime(), errno, qnx_getclock(), qnx_setclock(), ticksize utility


[Previous]
[Contents]
[Next]