p The .Fn timerfd_create system call creates a .Nm object using the clock specified in the .Fa clockid argument. Valid values for .Fa clockid are .Dv CLOCK_REALTIME and .Dv CLOCK_MONOTONIC . The following flags define the behavior of the resulting object: l -tag -width "TFD_NONBLOCK" t Dv TFD_CLOEXEC This is an alias for the .Dv O_CLOEXEC flag; see .Xr open 2 for more information. t Dv TFD_NONBLOCK This is an alias for the .Dv O_NONBLOCK flag; see .Xr open 2 for more information. .El
p Each time a .Nm timer expires, an internal counter is incremented. Reads from an .Nm object return the value of this counter in the caller's buffer as an unsigned 64-bit integer and reset the counter to .Dv 0 . If the value of the .Nm object's counter is .Dv 0 , then reads will block, unless the .Nm object is set for non-blocking I/O.
p Writes to a .Nm object are not supported.
p The .Fn timerfd_settime system call sets the next expiration time of the .Nm object to the .Va it_value
o see .Xr itimerspec 3
c specified in the .Fa tim argument. If the value is .Dv 0 , the timer is disarmed. If the argument .Fa otim is not .Dv NULL the old timer settings are returned. The following flags may be specified to alter the behavior of the timer: l -tag -width "TFD_TIMER_CANCEL_ON_SET" t Dv TFD_TIMER_ABSTIME The specified timer value is an absolute time. This is equivalent to specifying .Dv TIMER_ABSTIME to .Xr timer_settime 2 . Otherwise, the time value is a relative time, equivalent to specifying .Dv TIMER_RELTIME to .Xr timer_settime 2 . t Dv TFD_TIMER_CANCEL_ON_SET If the .Nm object's clock ID is .Dv CLOCK_REALTIME , then the timer will be cancelled and its file descriptor will become immediately readable if the system realtime clock is set using .Xr clock_settime 2 or .Xr settimeofday 2 . If the .Nm object's clock ID is not .Dv CLOCK_REALTIME this flag is ignored. .El
p If the .Va it_interval of the .Fa tim argument is non-zero, then the timer reloads upon expiration.
p The .Fn timerfd_gettime system call returns the current settings of the .Nm object in the .Fa tim argument. .Sh RETURN VALUES The .Fn timerfd_create system call returns .Dv -1 if an error occurs, otherwise the return value is a descriptor representing the .Nm object.
p The .Fn timerfd_gettime and .Fn timerfd_settime system calls return .Dv 0 upon success or .Dv -1 if an error occurs. .Sh ERRORS The .Fn timerfd system call fails if: l -tag -width Er t Bq Er EINVAL Flags other than .Dv TFD_CLOEXEC and .Dv TFD_NONBLOCK are set in the .Fa flags argument. t Bq Er EINVAL The .Fa clockid argument was something other than .Dv CLOCK_REALTIME or .Dv CLOCK_MONOTONIC . t Bq Er EMFILE The per-process descriptor table is full. t Bq Er ENFILE The system file table is full. .El
p The .Fn timerfd_gettime system call fails if: l -tag -width Er t Bq Er EBADF The argument .Fa fd is not a valid file descriptor. t Bq Er EINVAL The argument .Fa fd does not refer to a .Nm timerfd object. t Bq Er EFAULT The .Fa tim argument points outside the allocated address space. .El
p The .Fn timerfd_settime system call fails if: l -tag -width Er t Bq Er EBADF The argument .Fa fd is not a valid file descriptor. t Bq Er EINVAL The argument .Fa fd does not refer to a .Nm timerfd object. t Bq Er EINVAL Bits other than the defined .Dv TFD_TIMER_ABSTIME and .Dv TFD_TIMER_CANCEL_ON_SET bits are set in the .Fa flags argument. t Bq Er EINVAL A nanosecond field in the .Fa tim argument specified a value less than zero or greater than or equal to .Dv 10e9 . t Bq Er EFAULT The .Fa tim or .Fa otim arguments point outside the allocated address space. .El
p A read from a .Nm object fails if: l -tag -width Er t Bq Er EINVAL The size of the read buffer is less than 8 bytes
q the size required to hold an unsigned 64-bit integer . t Bq Er EAGAIN The value of the .Nm object's expiration counter is .Dv 0 and the .Nm object is set for non-blocking I/O. t Bq Er ECANCELED The .Nm object was created with the clock ID .Dv CLOCK_REALTIME , was configured with the .Dv TFD_TIMER_CANCEL_ON_SET flag, and the system realtime clock was changed with .Xr clock_settime 2 or .Xr settimeofday 2 . .El .Sh SEE ALSO .Xr clock_settime 2 , .Xr close 2 , .Xr kevent 2 , .Xr open 2 , .Xr poll 2 , .Xr read 2 , .Xr select 2 , .Xr settimeofday 2 , .Xr timer_create 2 , .Xr timer_gettime 2 , .Xr timer_settime 2 .Sh HISTORY The .Nm interface first appeared in .Nx 10 . It is compatible with the .Nm interface that appeared in Linux 2.6.25.