To sleep for 500ms:
#include <stdio.h>
#include <time.h>
int main() {
struct timespec ts = {
.tv_sec = 0,
.tv_nsec = 5e8,
};
printf("Sleep now!\n");
nanosleep(&ts, NULL);
printf("Sleeping done!\n");
return 0;
}