Which one of the two functions is better
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp);
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
The advantages of
ntpd, etc. With
nanosleepand precalculating the interval to sleep to reach a given absolute time, you'll fail to wake if the clock is reset and the desired time arrives "early". Also, there's a race condition with scheduling using interval times: If you compute the interval you want to sleep, but you get preempted before calling
nanosleepand don't get scheduled again for a while, you'll again sleep too long.