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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -