TIMERFD(3C) | Standard C Library Functions | TIMERFD(3C) |
timerfd_create
,
timerfd_settime
,
timerfd_gettime
— create and
manipulate timers via a file descriptor interface
#include
<sys/timerfd.h>
int
timerfd_create
(int clockid,
int flags);
int
timerfd_settime
(int fd,
int flags, const struct itimerspec
*restrict value, struct itimerspec *restrict
ovalue);
int
timerfd_gettime
(int fd,
struct itimerspec *value);
These routines create and manipulate timers in which events are
associated with a file descriptor, allowing for timer-based events to be
used in file-descriptor based facilities like
poll(2),
port_get(3C) or
epoll_wait(3C). The
timerfd_create
()
function creates a timer with the clock type specified by
clockid. The
CLOCK_REALTIME
and CLOCK_HIGHRES clock types, as defined in
timer_create(3C), are supported
by timerfd_create
(). (Note that
CLOCK_MONOTONIC
may be used as an alias for CLOCK_HIGHRES.)
The flags argument specifies additional parameters for the timer instance, and can have any of the following values:
timerfd_settime
()
or successful
read
().The following operations can be performed upon a timerfd instance:
timerfd_settime
().
Upon success, the number of expirations will be copied into the eight byte
buffer passed to the system call. If there have been no expirations of the
timer since the last successful
read(2) or
timerfd_sttime
(),
read(2) will block until at least the
next expiration, or return EAGAIN if the instance was
created with TFD_NONBLOCK. Note that if multiple threads
are blocked in read(2) for the same
timer, only one of them will return upon a single timer expiration.
If the buffer specified to read(2) is less than eight bytes in length, EINVAL will be returned.
Upon successful completion, a file descriptor associated with the instance is returned. Otherwise, -1 is returned and errno is set to indicate the error.
The timerfd_create
() function will fail
if:
EINAL
EMFILE
EPERM
poll(2), epoll_wait(3C), port_get(3C), timer_create(3C), timer_gettime(3C), timer_settime(3C), privileges(7), timerfd(7)
February 17, 2023 | OmniOS |