timer_settime(2) — Linux manual page


TIMER_SETTIME(2)          Linux Programmer's Manual         TIMER_SETTIME(2)

NAME         top

       timer_settime,  timer_gettime  -  arm/disarm and fetch state of POSIX
       per-process timer

SYNOPSIS         top

       #include <time.h>

       int timer_settime(timer_t timerid, int flags,
                         const struct itimerspec *new_value,
                         struct itimerspec *old_value);
       int timer_gettime(timer_t timerid, struct itimerspec *curr_value);

       Link with -lrt.

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       timer_settime(), timer_gettime(): _POSIX_C_SOURCE >= 199309L

DESCRIPTION         top

       timer_settime() arms or disarms the timer identified by timerid.  The
       new_value argument is pointer to an itimerspec structure that
       specifies the new initial value and the new interval for the timer.
       The itimerspec structure is defined as follows:

           struct timespec {
               time_t tv_sec;                /* Seconds */
               long   tv_nsec;               /* Nanoseconds */

           struct itimerspec {
               struct timespec it_interval;  /* Timer interval */
               struct timespec it_value;     /* Initial expiration */

       Each of the substructures of the itimerspec structure is a timespec
       structure that allows a time value to be specified in seconds and
       nanoseconds.  These time values are measured according to the clock
       that was specified when the timer was created by timer_create(2).

       If new_value->it_value specifies a nonzero value (i.e., either sub‐
       field is nonzero), then timer_settime() arms (starts) the timer, set‐
       ting it to initially expire at the given time.  (If the timer was al‐
       ready armed, then the previous settings are overwritten.)  If
       new_value->it_value specifies a zero value (i.e., both subfields are
       zero), then the timer is disarmed.

       The new_value->it_interval field specifies the period of the timer,
       in seconds and nanoseconds.  If this field is nonzero, then each time
       that an armed timer expires, the timer is reloaded from the value
       specified in new_value->it_interval.  If new_value->it_interval spec‐
       ifies a zero value, then the timer expires just once, at the time
       specified by it_value.

       By default, the initial expiration time specified in
       new_value->it_value is interpreted relative to the current time on
       the timer's clock at the time of the call.  This can be modified by
       specifying TIMER_ABSTIME in flags, in which case new_value->it_value
       is interpreted as an absolute value as measured on the timer's clock;
       that is, the timer will expire when the clock value reaches the value
       specified by new_value->it_value.  If the specified absolute time has
       already passed, then the timer expires immediately, and the overrun
       count (see timer_getoverrun(2)) will be set correctly.

       If the value of the CLOCK_REALTIME clock is adjusted while an abso‐
       lute timer based on that clock is armed, then the expiration of the
       timer will be appropriately adjusted.  Adjustments to the CLOCK_REAL‐
       TIME clock have no effect on relative timers based on that clock.

       If old_value is not NULL, then it points to a buffer that is used to
       return the previous interval of the timer (in old_value->it_interval)
       and the amount of time until the timer would previously have next ex‐
       pired (in old_value->it_value).

       timer_gettime() returns the time until next expiration, and the in‐
       terval, for the timer specified by timerid, in the buffer pointed to
       by curr_value.  The time remaining until the next timer expiration is
       returned in curr_value->it_value; this is always a relative value,
       regardless of whether the TIMER_ABSTIME flag was used when arming the
       timer.  If the value returned in curr_value->it_value is zero, then
       the timer is currently disarmed.  The timer interval is returned in
       curr_value->it_interval.  If the value returned in curr_value->it_in‐
       terval is zero, then this is a "one-shot" timer.

RETURN VALUE         top

       On success, timer_settime() and timer_gettime() return 0.  On error,
       -1 is returned, and errno is set to indicate the error.

ERRORS         top

       These functions may fail with the following errors:

       EFAULT new_value, old_value, or curr_value is not a valid pointer.

       EINVAL timerid is invalid.

       timer_settime() may fail with the following errors:

       EINVAL new_value.it_value is negative; or new_value.it_value.tv_nsec
              is negative or greater than 999,999,999.

VERSIONS         top

       These system calls are available since Linux 2.6.

CONFORMING TO         top

       POSIX.1-2001, POSIX.1-2008.

EXAMPLES         top

       See timer_create(2).

SEE ALSO         top

       timer_create(2), timer_getoverrun(2), time(7)

COLOPHON         top

       This page is part of release 5.09 of the Linux man-pages project.  A
       description of the project, information about reporting bugs, and the
       latest version of this page, can be found at

Linux                            2020-06-09                 TIMER_SETTIME(2)

Pages that refer to this page: getitimer(2)setitimer(2)syscalls(2)timer_create(2)timer_delete(2)timerfd_create(2)timerfd_gettime(2)timerfd_settime(2)timer_getoverrun(2)aiocb(3)clockid_t(3)clock_t(3)dev_t(3)div_t(3)double_t(3)fenv_t(3)fexcept_t(3)file(3)FILE(3)float_t(3)gid_t(3)id_t(3)imaxdiv_t(3)int16_t(3)int32_t(3)int64_t(3)int8_t(3)intmax_t(3)intn_t(3)intN_t(3)intptr_t(3)lconv(3)ldiv_t(3)lldiv_t(3)off_t(3)pid_t(3)ptrdiff_t(3)regex_t(3)regmatch_t(3)regoff_t(3)siginfo_t(3)sigset_t(3)sigval(3)size_t(3)ssize_t(3)suseconds_t(3)timer_t(3)timespec(3)time_t(3)timeval(3)ualarm(3)uid_t(3)uint16_t(3)uint32_t(3)uint64_t(3)uint8_t(3)uintmax_t(3)uintn_t(3)uintN_t(3)uintptr_t(3)usleep(3)va_list(3)void(3)signal-safety(7)system_data_types(7)time_namespaces(7)