timerfd_create

Creates a new timer object.

The file descriptor supports the following operations:

read(2) If the timer has already expired one or more times since its settings were last modified using timerfd_settime(), or since the last successful read(2), then the buffer given to read(2) returns an unsigned 8-byte integer (uint64_t) containing the number of expirations that have occurred. (The returned value is in host byte order, i.e., the native byte order for integers on the host machine.)

If no timer expirations have occurred at the time of the read(2), then the call either blocks until the next timer expiration, or fails with the error EAGAIN if the file descriptor has been made non-blocking (via the use of the fcntl(2) F_SETFL operation to set the O_NONBLOCK flag).

A read(2) will fail with the error EINVAL if the size of the supplied buffer is less than 8 bytes.

poll(2), select(2) (and similar) The file descriptor is readable (the select(2) readfds argument; the poll(2) POLLIN flag) if one or more timer expirations have occurred.

The file descriptor also supports the other file-descriptor multiplexing APIs: pselect(2), ppoll(2), and epoll(7).

close(2) When the file descriptor is no longer required it should be closed. When all file descriptors associated with the same timer object have been closed, the timer is disarmed and its resources are freed by the kernel.

fork(2) semantics After a fork(2), the child inherits a copy of the file descriptor created by timerfd_create(). The file descriptor refers to the same underlying timer object as the corresponding file descriptor in the parent, and read(2)s in the child will return information about expirations of the timer.

execve(2) semantics A file descriptor created by timerfd_create() is preserved across execve(2), and continues to generate timer expirations if the timer was armed.

extern (C)
int
timerfd_create
(,
int flags = 0
)

Parameters

clockid int

Specifies the clock that is used to mark the progress of the timer, and must be either CLOCK_REALTIME or CLOCK_MONOTONIC. - CLOCK_REALTIME is a settable system-wide clock. - CLOCK_MONOTONIC is a non-settable clock that is not affected by discontinuous changes in the system clock (e.g., manual changes to system time). The current value of each of these clocks can be retrieved using clock_gettime(2).

flags int

Starting with Linux 2.6.27: 0 or a bitwise OR combination of - TFD_NONBLOCK: Set the O_NONBLOCK file status flag on the new open file description. - TFD_CLOEXEC: Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. (See the description of the O_CLOEXEC flag in open(2) for reasons why this may be useful.)

Up to Linux version 2.6.26: Must be 0.

Return Value

Type: int

a file descriptor that refers to that timer

Meta