/* compile with unpatched sys/features.h */ #define _POSIX_MONOTONIC_CLOCK 200112L #include #include #include int main(void) { int n, ret; struct timespec *res; ret = clock_getres(CLOCK_MONOTONIC, res); if (ret < 0) { printf("ERROR: clock_getres(CLOCK_MONOTONIC) failed\n"); return ret; } printf("%ld:%ld\n", res->tv_sec, res->tv_nsec); n = 0; while (n < 5) { sleep(1); ret = clock_gettime(CLOCK_MONOTONIC, res); if (ret < 0) { printf("ERROR: clock_gettime(CLOCK_MONOTONIC) failed\n"); return ret; } printf("%ld:%09ld\n", res->tv_sec, res->tv_nsec); n++; } ret = clock_setres(CLOCK_MONOTONIC, res); if (ret != -1) { printf("ERROR: clock_setres(CLOCK_MONOTONIC) must fail\n"); return -1; } return 0; }