posix - How to use nanosleep() in C? What are `tim.tv_sec` and `tim.tv_nsec`? -
what use of tim.tv_sec
, tim.tv_nsec
in following?
how can sleep execution 500000
microseconds?
#include <stdio.h> #include <time.h> int main() { struct timespec tim, tim2; tim.tv_sec = 1; tim.tv_nsec = 500; if(nanosleep(&tim , &tim2) < 0 ) { printf("nano sleep system call failed \n"); return -1; } printf("nano sleep successfull \n"); return 0; }
half second 500,000,000 nanoseconds, code should read:
tim.tv_sec = 0; tim.tv_nsec = 500000000l;
as things stand, code sleeping 1.0000005s (1s + 500ns).
Comments
Post a Comment