summaryrefslogtreecommitdiffstats
path: root/man2/timer_settime.2
blob: 030bab543f9c4ced70d34ed100d9a778e48a1e35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
.\"     <mtk.manpages@gmail.com>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH timer_settime 2 2023-03-30 "Linux man-pages 6.05.01"
.SH NAME
timer_settime, timer_gettime \- arm/disarm and fetch
state of POSIX per-process timer
.SH LIBRARY
Real-time library
.RI ( librt ", " \-lrt )
.SH SYNOPSIS
.nf
.B  #include <time.h>
.PP
.BI "int timer_gettime(timer_t " timerid ", struct itimerspec *" curr_value );
.BI "int timer_settime(timer_t " timerid ", int " flags ,
.BI "                  const struct itimerspec *restrict " new_value ,
.BI "                  struct itimerspec *_Nullable restrict " old_value );
.fi
.PP
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
.PP
.BR timer_settime (),
.BR timer_gettime ():
.nf
    _POSIX_C_SOURCE >= 199309L
.fi
.SH DESCRIPTION
.BR timer_settime ()
arms or disarms the timer identified by
.IR timerid .
The
.I new_value
argument is pointer to an
.I itimerspec
structure that specifies the new initial value and
the new interval for the timer.
The
.I itimerspec
structure is described in
.BR itimerspec (3type).
.PP
Each of the substructures of the
.I itimerspec
structure is a
.BR timespec (3)
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
.BR timer_create (2).
.PP
If
.I new_value\->it_value
specifies a nonzero value (i.e., either subfield is nonzero), then
.BR timer_settime ()
arms (starts) the timer,
setting it to initially expire at the given time.
(If the timer was already armed,
then the previous settings are overwritten.)
If
.I new_value\->it_value
specifies a zero value
(i.e., both subfields are zero),
then the timer is disarmed.
.PP
The
.I 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
.IR new_value\->it_interval .
If
.I new_value\->it_interval
specifies a zero value,
then the timer expires just once, at the time specified by
.IR it_value .
.PP
By default, the initial expiration time specified in
.I 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
.B TIMER_ABSTIME
in
.IR flags ,
in which case
.I 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
.IR new_value\->it_value .
If the specified absolute time has already passed,
then the timer expires immediately,
and the overrun count (see
.BR timer_getoverrun (2))
will be set correctly.
.\" By experiment: the overrun count is set correctly, for CLOCK_REALTIME.
.PP
If the value of the
.B CLOCK_REALTIME
clock is adjusted while an absolute timer based on that clock is armed,
then the expiration of the timer will be appropriately adjusted.
Adjustments to the
.B CLOCK_REALTIME
clock have no effect on relative timers based on that clock.
.\" Similar remarks might apply with respect to process and thread CPU time
.\" clocks, but these clocks are not currently (2.6.28) settable on Linux.
.PP
If
.I old_value
is not NULL, then it points to a buffer
that is used to return the previous interval of the timer (in
.IR old_value\->it_interval )
and the amount of time until the timer
would previously have next expired (in
.IR old_value\->it_value ).
.PP
.BR timer_gettime ()
returns the time until next expiration, and the interval,
for the timer specified by
.IR timerid ,
in the buffer pointed to by
.IR curr_value .
The time remaining until the next timer expiration is returned in
.IR curr_value\->it_value ;
this is always a relative value, regardless of whether the
.B TIMER_ABSTIME
flag was used when arming the timer.
If the value returned in
.I curr_value\->it_value
is zero, then the timer is currently disarmed.
The timer interval is returned in
.IR curr_value\->it_interval .
If the value returned in
.I curr_value\->it_interval
is zero, then this is a "one-shot" timer.
.SH RETURN VALUE
On success,
.BR timer_settime ()
and
.BR timer_gettime ()
return 0.
On error, \-1 is returned, and
.I errno
is set to indicate the error.
.SH ERRORS
These functions may fail with the following errors:
.TP
.B EFAULT
.IR new_value ,
.IR old_value ,
or
.I curr_value
is not a valid pointer.
.TP
.B EINVAL
.I timerid
is invalid.
.\" FIXME . eventually: invalid value in flags
.PP
.BR timer_settime ()
may fail with the following errors:
.TP
.B EINVAL
.I new_value.it_value
is negative; or
.I new_value.it_value.tv_nsec
is negative or greater than 999,999,999.
.SH STANDARDS
POSIX.1-2008.
.SH HISTORY
Linux 2.6.
POSIX.1-2001.
.SH EXAMPLES
See
.BR timer_create (2).
.SH SEE ALSO
.BR timer_create (2),
.BR timer_getoverrun (2),
.BR timespec (3),
.BR time (7)