#include #include #include #include #include #include #include int main(void) { int fd; struct timespec t0, t1, dt; const struct itimerspec its = { .it_value = { .tv_sec = 1, .tv_nsec = 0 }, .it_interval = { .tv_sec = 0, .tv_nsec = 0 }, }; uint64_t v; ssize_t nread; int error; if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC)) == -1) err(1, "timerfd_create"); if (timerfd_settime(fd, /*flags (relative)*/0, &its, NULL) == -1) err(1, "timerfd_settime"); if (clock_gettime(CLOCK_MONOTONIC, &t0) == -1) err(1, "clock_gettime"); if ((nread = read(fd, &v, sizeof(v))) == -1) err(1, "read"); if (clock_gettime(CLOCK_MONOTONIC, &t1) == -1) err(1, "clock_gettime"); if ((size_t)nread != sizeof(v)) errx(1, "bad read: %zd", nread); printf("%"PRIu64"\n", v); timespecsub(&t1, &t0, &dt); printf("%jd.%09ld\n", (intmax_t)dt.tv_sec, dt.tv_nsec); fflush(stdout); return ferror(stdout); }