1TIMER_SETTIME(2)           Linux Programmer's 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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

92       These functions may fail with the following errors:
93
94       EFAULT new_value, old_value, or curr_value is not a valid pointer.
95
96       EINVAL timerid is invalid.
97
98       timer_settime() may fail with the following errors:
99
100       EINVAL new_value.it_value is negative; or new_value.it_value.tv_nsec is
101              negative or greater than 999,999,999.
102

VERSIONS

104       These system calls are available since Linux 2.6.
105

CONFORMING TO

107       POSIX.1-2001
108

EXAMPLE

110       See timer_create(2).
111

SEE ALSO

113       timer_create(2), timer_settime(2), timer_getoverrun(2), time(7)
114

COLOPHON

116       This  page  is  part of release 3.25 of the Linux man-pages project.  A
117       description of the project, and information about reporting  bugs,  can
118       be found at http://www.kernel.org/doc/man-pages/.
119
120
121
122Linux                             2009-02-20                  TIMER_SETTIME(2)
Impressum