TIMESPEC_GET(3C) Standard C Library Functions TIMESPEC_GET(3C)

timespec_get, timespec_getresget time information

#include <time.h>

int
timespec_get(struct timespec *ts, int base);

int
timespec_getres(struct timespec *ts, int base);

The () function provides access to nanosecond resolution time. The () function provides access to the underlying clock's resolution. The meaning and source of time is defined by the base argument. The following values are defined for base:

Obtain the current time of day from the realtime clock on the system. It represents the amount of time in second and nanoseconds since the Epoch. This is logically equivalent to calling clock_gettime(3C) with CLOCK_REALTIME.
The system's monotonic clock is a non-adjustable, high-resolution clock. The returned value is not subject to adjustments from time of day drift nor can it be set. This clock is generally only useful for measuring elapsed time relative to a prior reading. This is logically equivalent to using the CLOCK_HIGHRES and CLOCK_MONOTONIC clocks or calling gethrtime(3C).
This clock measures the elapsed system and user CPU-time of the current thread. The amount of time it has spent executing code is measured in seconds and nanoseconds. The pr_utime member of the lwpsinfo_t or prusage_t structures discussed in proc(5) are alternative ways to see the user component. The system component is a combination of both the system and trap time that the thread has experienced. In the lwpsinfo_t this is covered solely by the pr_stime member. For the prusage_t these are separated out into the pr_stime and pr_ttime members respectively.

This is logically equivalent to using the CLOCK_THREAD_CPUTIME_ID clock . This clock is optional and may not be present on other platforms.

This clock is similar to the TIME_THREAD_ACTIVE clock, except it only counts user time that has elapsed. This is logically equivalent to using the CLOCK_VIRTUAL clock or calling gethrvtime(3C). This clock is an extension and may not be available on other platforms.
This clock measures the elapsed system and user CPU-time of the current process, including all of its threads. None of the process's children are counted in this measure, whether running or terminated. The value read here will be the same as combining the corresponding proc(5) psinfo_t structure's pr_stime and pr_utime members. This clock is optional and may not be present on other platforms.

For the definition of the timespec structure, see time.h(3HEAD).

Upon successful completion, the timespec_get() and timespec_getres() functions return the passed in value of base. Otherwise, is returned to represent an error.

Unlike other functions, the timespec_get() and timespec_getres() functions are not defined to set errno. However, the timespec_get() and timespec_getres() functions will fail if:

clock_getres(3C), clock_gettime(3C), gethrtime(3C), gethrvtime(3C), time.h(3HEAD), attributes(7)

January 12, 2025 OmniOS