timerfd_create()¶
Purpose¶
Creates a file descriptor that becomes readable when a timer expires.
Header¶
Prototype¶
Parameters¶
clockid: commonlyCLOCK_MONOTONICorCLOCK_REALTIME.flags: commonlyTFD_CLOEXEC,TFD_NONBLOCK, or both.
Return Value¶
- Success: returns a timer fd.
- Failure: returns
-1and setserrno.
Minimal Example¶
Common Pitfalls¶
- Prefer
CLOCK_MONOTONICfor relative timers. - Read the timer fd after it becomes readable, otherwise epoll will keep reporting it.
- The read size must be
sizeof(uint64_t).