- NetBSD Manual Pages
CLOCK_SETTIME(2) NetBSD System Calls Manual CLOCK_SETTIME(2)
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
clock_settime, clock_gettime, clock_getres -- clock and timer functions
Standard C Library (libc, -lc)
clock_settime(clockid_t clock_id, const struct timespec *tp);
clock_gettime(clockid_t clock_id, struct timespec *tp);
clock_getres(clockid_t clock_id, struct timespec *res);
The clock_settime() function sets the clock identified by clock_id to the
absolute time specified by tp. If the time specified by tp is not a mul-
tiple of the resolution of the clock, tp is truncated to a multiple of
The clock_gettime() function stores the time of the clock identified by
clock_id into the location specified by tp.
The clock_getres() function stores the resolution of the clock identified
by clock_id into the location specified by res, unless res is NULL.
The following clock_id values are supported:
CLOCK_REALTIME identifies the realtime clock for the system. For this
clock, the values specified by clock_settime() and
obtained by clock_gettime() represent the amount of time
(in seconds and nanoseconds) since 00:00 Universal Coor-
dinated Time, January 1, 1970.
CLOCK_MONOTONIC identifies a clock that increases at a steady rate
(monotonically). This clock is not affected by calls to
adjtime(2) and settimeofday(2) and will fail with an
EINVAL error if it's the clock specified in a call to
clock_settime(). The origin of the clock is unspeci-
CLOCK_VIRTUAL identifies a clock that increments only when the CPU is
running in user mode on behalf of the calling process.
CLOCK_PROF identifies a clock that increments when the CPU is run-
ning in user or kernel mode on behalf of the calling
identifies a per process clock based on tick values.
This clock is not settable.
identifies a per thread clock based on tick values.
This clock is not settable.
If the calling user is not the super-user, the clock_settime() system
call will fail, and the clock_settime() function in the standard C
library will try to use the clockctl(4) device if present, thus making it
possible for non privileged users to set the system time. If clockctl(4)
is not present or not accessible, then clock_settime() returns EPERM.
A value of 0 is returned on success. Otherwise, a value of -1 is
returned and errno is set to indicate the error.
The clock_settime(), clock_gettime() and clock_getres() functions will
[EINVAL] The clock_id argument does not specify a known clock.
[ENOSYS] The function is not supported by this implementation.
The clock_settime() function will fail if:
[EINVAL] The tp argument is outside the range for the specified
clock, clock_id; or the tp argument specified a
nanosecond value less than zero of greater than or
equal 1000 million; or the clock_id argument is a
clock that can not be adjusted.
[EPERM] The calling process does not have the appropriate
privilege to set the specified clock, clock_id.
The clock_gettime() function will fail if:
[EFAULT] The tp argument specifies an address that is not a
valid part of the process address space.
ctime(3), time(3), clockctl(4)
The clock_settime(), clock_gettime() and clock_getres() functions conform
to IEEE Std 1003.1b-1993 (``POSIX.1'').
NetBSD 9.3 September 23, 2016 NetBSD 9.3