1timer_settime(2)              System Calls Manual             timer_settime(2)
2
3
4

NAME

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

LIBRARY

10       Real-time library (librt, -lrt)
11

SYNOPSIS

13       #include <time.h>
14
15       int timer_gettime(timer_t timerid, struct itimerspec *curr_value);
16       int timer_settime(timer_t timerid, int flags,
17                         const struct itimerspec *restrict new_value,
18                         struct itimerspec *_Nullable restrict old_value);
19
20   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22       timer_settime(), timer_gettime():
23           _POSIX_C_SOURCE >= 199309L
24

DESCRIPTION

26       timer_settime() arms or disarms the timer identified by  timerid.   The
27       new_value argument is pointer to an itimerspec structure that specifies
28       the new initial value and the new interval for the timer.  The  itimer‐
29       spec structure is described in itimerspec(3type).
30
31       Each  of the substructures of the itimerspec structure is a timespec(3)
32       structure that allows a time value  to  be  specified  in  seconds  and
33       nanoseconds.   These  time  values  are measured according to the clock
34       that was specified when the timer was created by timer_create(2).
35
36       If new_value->it_value specifies a nonzero value (i.e., either subfield
37       is  nonzero),  then timer_settime() arms (starts) the timer, setting it
38       to initially expire at the given  time.   (If  the  timer  was  already
39       armed,    then    the   previous   settings   are   overwritten.)    If
40       new_value->it_value specifies a zero value (i.e.,  both  subfields  are
41       zero), then the timer is disarmed.
42
43       The  new_value->it_interval field specifies the period of the timer, in
44       seconds and nanoseconds.  If this field is nonzero, then each time that
45       an  armed timer expires, the timer is reloaded from the value specified
46       in new_value->it_interval.  If new_value->it_interval specifies a  zero
47       value,  then  the  timer  expires  just  once, at the time specified by
48       it_value.
49
50       By   default,   the    initial    expiration    time    specified    in
51       new_value->it_value  is interpreted relative to the current time on the
52       timer's clock at the time of the call.  This can be modified by  speci‐
53       fying  TIMER_ABSTIME in flags, in which case new_value->it_value is in‐
54       terpreted as an absolute value as measured on the timer's  clock;  that
55       is, the timer will expire when the clock value reaches the value speci‐
56       fied by new_value->it_value.  If the specified absolute  time  has  al‐
57       ready passed, then the timer expires immediately, and the overrun count
58       (see timer_getoverrun(2)) will be set correctly.
59
60       If the value of the CLOCK_REALTIME clock is adjusted while an  absolute
61       timer  based  on  that clock is armed, then the expiration of the timer
62       will be appropriately  adjusted.   Adjustments  to  the  CLOCK_REALTIME
63       clock have no effect on relative timers based on that clock.
64
65       If  old_value  is  not NULL, then it points to a buffer that is used to
66       return the previous interval of the timer  (in  old_value->it_interval)
67       and  the  amount of time until the timer would previously have next ex‐
68       pired (in old_value->it_value).
69
70       timer_gettime() returns the time until next expiration, and the  inter‐
71       val,  for  the  timer specified by timerid, in the buffer pointed to by
72       curr_value.  The time remaining until the next timer expiration is  re‐
73       turned  in  curr_value->it_value;  this is always a relative value, re‐
74       gardless of whether the TIMER_ABSTIME flag was  used  when  arming  the
75       timer.  If the value returned in curr_value->it_value is zero, then the
76       timer is  currently  disarmed.   The  timer  interval  is  returned  in
77       curr_value->it_interval.   If  the value returned in curr_value->it_in‐
78       terval is zero, then this is a "one-shot" timer.
79

RETURN VALUE

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

ERRORS

85       These functions may fail with the following errors:
86
87       EFAULT new_value, old_value, or curr_value is not a valid pointer.
88
89       EINVAL timerid is invalid.
90
91       timer_settime() may fail with the following errors:
92
93       EINVAL new_value.it_value is negative; or new_value.it_value.tv_nsec is
94              negative or greater than 999,999,999.
95

STANDARDS

97       POSIX.1-2008.
98

HISTORY

100       Linux 2.6.  POSIX.1-2001.
101

EXAMPLES

103       See timer_create(2).
104

SEE ALSO

106       timer_create(2), timer_getoverrun(2), timespec(3), time(7)
107
108
109
110Linux man-pages 6.05              2023-03-30                  timer_settime(2)
Impressum