title: How to use nanosleep() in C? What are `tim.tv_sec` and `tim.tv_nsec`?
body: <p>What is the use of <code>tim.tv_sec</code> and <code>tim.tv_nsec</code> in the following?</p>
  
  <p>How can I sleep execution for <code>500000</code> microseconds?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  int main()
  {
     struct timespec tim, tim2;
     tim.tv_sec = 1;
     tim.tv_nsec = 500;
  
     if(nanosleep(&amp;tim , &amp;tim2) &lt; 0 )   
     {
        printf("Nano sleep system call failed \n");
        return -1;
     }
  
     printf("Nano sleep successfull \n");
  
     return 0;
  }
  </code></pre>