timerfd API Reference¶
Header¶
Core APIs¶
int timerfd_create(int clockid, int flags);
int timerfd_settime(int fd, int flags,
const struct itimerspec *new_value,
struct itimerspec *old_value);
int timerfd_gettime(int fd, struct itimerspec *curr_value);
Common Flags¶
| Flag | Purpose |
|---|---|
TFD_NONBLOCK |
Create non-blocking timerfd |
TFD_CLOEXEC |
Close fd across exec() |
TFD_TIMER_ABSTIME |
Use absolute expiration time |
Expiration Read Format¶
The read value is the number of expirations since the previous read.
Common Pitfalls¶
- Always read 8 bytes from the timerfd.
- Forgetting to read causes repeated readiness events.
read()returns expiration count, not timestamp.- Prefer one global timerfd plus software state for many similar timeout checks.