svcadm(8)을 검색하려면 섹션에서 8 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
clock_gettime(3c)
clock_settime(3C) Standard C Library Functions clock_settime(3C)
NAME
clock_settime, clock_gettime, clock_getres, timespec_get - high-resolu‐
tion clock operations
SYNOPSIS
#include <time.h>
int clock_settime(clockid_t clock_id, const struct timespec *tp);
int clock_gettime(clockid_t clock_id, struct timespec *tp);
int clock_getres(clockid_t clock_id, struct timespec *res);
int timespec_get(struct timespec *ts, int base);
DESCRIPTION
The clock_settime() function sets the specified clock, clock_id, to the
value specified by tp. Time values that are between two consecutive
non-negative integer multiples of the resolution of the specified clock
are truncated down to the smaller multiple of the resolution.
The clock_gettime() function returns the current value tp for the spec‐
ified clock, clock_id.
The resolution of any clock can be obtained by calling clock_getres().
Clock resolutions are system-dependent and cannot be set by a process.
If the argument res is not NULL, the resolution of the specified clock
is stored in the location pointed to by res. If res is NULL, the clock
resolution is not returned. If the time argument of clock_settime() is
not a multiple of res, then the value is truncated to a multiple of
res.
A clock may be systemwide (that is, visible to all processes) or per-
process (measuring time that is meaningful only within a process).
A clock_id of CLOCK_REALTIME is defined in <time.h>. This clock repre‐
sents the realtime clock for the system. For this clock, the values re‐
turned by clock_gettime() and specified by clock_settime() represent
the amount of time (in seconds and nanoseconds) since the Epoch.
A clock_id of CLOCK_HIGHRES represents the non-adjustable, high-resolu‐
tion clock for the system. For this clock, the value returned by
clock_gettime() represents the amount of time (in seconds and nanosec‐
onds) since some arbitrary time in the past; it is not correlated in
any way to the time of day, and thus is not subject to resetting or
drifting by way of adjtime(2), ntp_adjtime(2), settimeofday(3C), or
clock_settime(). The time source for this clock is the same as that for
gethrtime(3C).
A clock_id of CLOCK_MONOTONIC represents the system-wide monotonic
clock, which is defined as a clock whose value cannot be set with
clock_settime() and that cannot have backward clock jumps.
A clock_id of CLOCK_PROCESS_CPUTIME_ID represents the CPU-time clock of
the calling process when invoking one of the clock_*() or timer_*()
functions.
A clock_id of CLOCK_THREAD_CPUTIME_ID represents the CPU-time clock as‐
sociated with the calling thread when invoking one of the clock_*() or
timer_*() functions.
The timespec_get() function modifies the timespec object pointed to by
ts to hold the current calendar time, based on the defined time base.
If base is TIME_UTC, tv_sec is set to the number of seconds since
epoch, truncated to a whole value. The implementation defines epoch, in
this case, the standard UNIX epoch of January 1, 1970. tv_nsec is set
to the integral number of nanoseconds, rounded to the resolution of the
system clock. The timespec_get() function is specified in the C11 stan‐
dard (INCITS/ISO/IEC 9899:2011).
Additional clocks may also be supported. The interpretation of time
values for these clocks is unspecified.
RETURN VALUES
Upon successful completion, the clock_settime(), clock_gettime(), and
clock_getres() functions return 0. Otherwise, -1 is returned and errno
is set to indicate the error.
Upon successful completion, the timespec_get() function returns the
nonzero value of base, otherwise, 0 is returned.
ERRORS
The clock_settime(), clock_gettime(), clock_getres(), and time‐
spec_get() functions will fail if:
EINVAL The clock_id argument does not specify a known clock, or the
base argument does not specify a known time base.
ENOSYS The functions clock_settime(), clock_gettime(), and clock_ge‐
tres() are not supported by this implementation.
The clock_settime() function will fail if:
EINVAL The tp argument to clock_settime() is outside the range for
the given clock ID; or the tp argument specified a nanosecond
value less than zero or greater than or equal to 1000 mil‐
lion.
The clock_settime() function may fail if:
EPERM The requesting process does not have the appropriate priv‐
ilege to set the specified clock.
EINTR The calling process belongs to a non-global zone and re‐
ceived a signal while setting the time.
ECANCELED The calling process belongs to a non-global zone and there
exists an internal I/O error.
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
TRIBUTE VALUE _ Interface StabilityCommitted _ MT-Levelclock_gettime()
is Async-Signal-Safe _ StandardSee standards(7).
SEE ALSO
time(2), ctime(3C), gethrtime(3C), timer_gettime(3C), timespeccmp(3C),
clock_getcpuclockid(3C), pthread_getcpuclockid(3C), time.h(3HEAD), at‐
tributes(7), standards(7)
HISTORY
The timespec_get() function was added in Oracle Solaris 11.4.0.
The clock_getres(), clock_gettime(), and clock_settime() functions were
added in Solaris 2.3.
Definitions for the following clock_id values are available in Solaris
starting with the listed release:
tab() box; cw(4.4i) |cw(1.1i) lw(4.4i) |lw(1.1i) CLOCK IDRELEASE _ T{
CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID T}10 1/06 (Update 1)
_ CLOCK_MONOTONIC10 3/05 _ CLOCK_HIGHRES8 _ CLOCK_REALTIME,
CLOCK_VIRTUAL2.3
Oracle Solaris 11.4 27 Aug 2025 clock_settime(3C)