15. Clock Manager

15.1. Introduction

The clock manager provides services two primary classes of services. The first focuses on obtaining and setting the current date and time. The other category of services focus on allowing a thread to delay for a specific length of time.

The directives provided by the clock manager are:

15.2. Background

There is currently no text in this section.

15.3. Operations

There is currently no text in this section.

15.4. Directives

This section details the clock manager’s directives. A subsection is dedicated to each of this manager’s directives and describes the calling sequence, related constants, usage, and status codes.

15.4.1. clock_gettime - Obtain Time of Day

CALLING SEQUENCE:

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

STATUS CODES:

On error, this routine returns -1 and sets errno to one of the following:

EINVAL The tp pointer parameter is invalid.
EINVAL The clock_id specified is invalid.

DESCRIPTION:

NOTES:

NONE

15.4.2. clock_settime - Set Time of Day

CALLING SEQUENCE:

#include <time.h>
int clock_settime(
    clockid_t              clock_id,
    const struct timespec *tp
);

STATUS CODES:

On error, this routine returns -1 and sets errno to one of the following:

EINVAL The tp pointer parameter is invalid.
EINVAL The clock_id specified is invalid.
EINVAL The contents of the tp structure are invalid.

DESCRIPTION:

NOTES:

NONE

15.4.3. clock_getres - Get Clock Resolution

CALLING SEQUENCE:

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

STATUS CODES:

On error, this routine returns -1 and sets errno to one of the following:

EINVAL The res pointer parameter is invalid.
EINVAL The clock_id specified is invalid.

DESCRIPTION:

NOTES:

If res is NULL, then the resolution is not returned.

15.4.4. sleep - Delay Process Execution

CALLING SEQUENCE:

#include <unistd.h>
unsigned int sleep(
    unsigned int seconds
);

STATUS CODES:

This routine returns the number of unslept seconds.

DESCRIPTION:

The sleep() function delays the calling thread by the specified number of seconds.

NOTES:

This call is interruptible by a signal.

15.4.5. usleep - Delay Process Execution in Microseconds

CALLING SEQUENCE:

#include <time.h>
useconds_t usleep(
    useconds_t useconds
);

STATUS CODES:

This routine returns the number of unslept seconds.

DESCRIPTION:

The sleep() function delays the calling thread by the specified number of seconds.

The usleep() function suspends the calling thread from execution until either the number of microseconds specified by the useconds argument has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process.

Because of other activity, or because of the time spent in processing the call, the actual length of time the thread is blocked may be longer than the amount of time specified.

NOTES:

This call is interruptible by a signal.

The Single UNIX Specification allows this service to be implemented using the same timer as that used by the alarm() service. This is NOT the case for RTEMS and this call has no interaction with the SIGALRM signal.

15.4.6. nanosleep - Delay with High Resolution

CALLING SEQUENCE:

#include <time.h>
int nanosleep(
    const struct timespec *rqtp,
    struct timespec       *rmtp
);

STATUS CODES:

On error, this routine returns -1 and sets errno to one of the following:

EINTR The routine was interrupted by a signal.
EAGAIN The requested sleep period specified negative seconds or nanoseconds.
EINVAL The requested sleep period specified an invalid number for the nanoseconds field.

DESCRIPTION:

NOTES:

This call is interruptible by a signal.

15.4.7. gettimeofday - Get the Time of Day

CALLING SEQUENCE:

#include <sys/time.h>
#include <unistd.h>
int gettimeofday(
    struct timeval  *tp,
    struct timezone *tzp
);

STATUS CODES:

On error, this routine returns -1 and sets errno as appropriate.

EPERM settimeofdat is called by someone other than the superuser.
EINVAL Timezone (or something else) is invalid.
EFAULT One of tv or tz pointed outside your accessible address space

DESCRIPTION:

This routine returns the current time of day in the tp structure.

NOTES:

Currently, the timezone information is not supported. The tzp argument is ignored.

15.4.8. time - Get time in seconds

CALLING SEQUENCE:

#include <time.h>
int time(
    time_t *tloc
);

STATUS CODES:

This routine returns the number of seconds since the Epoch.

DESCRIPTION:

time returns the time since 00:00:00 GMT, January 1, 1970, measured in seconds

If tloc in non null, the return value is also stored in the memory pointed to by t.

NOTES:

NONE