[Previous]
[Contents]
[Next]

qnx_getclock()

get the current time from a clock

Synopsis:

#include <time.h>
int qnx_getclock( pid_t proc_pid,
                  clockid_t clock_id,
                  struct timespec *tp )

Description:

The qnx_getclock() function gets the current time of the clock of type clock_id into the buffer pointed to by tp from the node identified by proc_pid. If proc_pid is zero, the current node is used.

To get the time on another node, proc_pid should be passed as a virtual circuit to the process manager on that node. For example,

/* Attach a vc to the process manager on node 4 */
proc_pid = qnx_vc_attach( 4, PROC_PID, 0, 0 );

The only supported clock type is CLOCK_REALTIME.

The tp parameter points to a timespec structure containing:

time_t    tv_sec;
time_t    tv_nsec;

The tv_sec member contains the number of seconds since 1970. The tv_nsec member contains the number of nanoseconds in the current second. This value increases by some multiple of nanoseconds, based upon the system timer's period.

Returns:

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

Examples:

/*
 * This program synchronizes the system clock of the
 * node it's running on with the system clock of the
 * node address provided as the first argument.
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/vc.h>
#include <sys/kernel.h>

void main( int argc, char **argv )
  {
    nid_t node;
    pid_t procpid;
    struct timespec gtime;

    node = strtol( argv[1], NULL, 0 );
    if( ( procpid = qnx_vc_attach( node, PROC_PID, 0,
                _VC_AT_SHARE ) ) == -1 ) {
       perror( "qnx_vc_attach" );
       exit( EXIT_FAILURE );
    }
    if( qnx_getclock( procpid, CLOCK_REALTIME, &gtime )
       == -1 ) {
      perror( "qnx_getclock" );
      exit( EXIT_FAILURE );
    }
    if( qnx_setclock( PROC_PID, CLOCK_REALTIME, &gtime )
       == -1 ) {
      perror( "qnx_setclock" );
      exit( EXIT_FAILURE );
    }
    qnx_vc_detach( procpid );
    exit( 0 );
  }

Classification:

QNX

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

See also:

clock_gettime(), clock_setres(), clock_settime(), errno, qnx_vc_attach()


[Previous]
[Contents]
[Next]