title: Clock function usleep not working right in c program ?
body: <p>I want to delay my program for 500 msec using clock_t type .For example i have following code  : </p>
  
  <pre><code>#include &lt;time.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main()
  {
     clock_t start_t, end_t, total_t,start_2,end_2,total_2;
     int i;
  
     start_t = clock();
     printf("start_t = %ld\n", start_t);
  
     //do a loop
     for(i=0; i&lt; 10000000; i++)
     {
     }
  
     end_t = clock();
  
  
     printf("end_t = %ld \n", end_t);
  
     total_t = (double)(end_t - start_t)*1000 / CLOCKS_PER_SEC;
     printf("Total1 in msec %ld \n",total_t);
  
  
  
     start_2=clock();
     printf("start_2 %ld\n ", start_2);
     usleep(500000);
  
     end_2=clock();
     printf("end_2 %ld\n ", end_2);
     total_2=(double)(start_2-end_2)*1000/CLOCKS_PER_SEC;
     printf("Total2 in msec %ld\n ", total_2);
  
  
     return(0);
  }
  </code></pre>
  
  <p>I have found out that usleep takes a value of μsec as an input. So i put 500000. </p>
  
  <p>But i get : </p>
  
  <pre><code>start_t = 1041
  end_t = 50441 
  Total1 in msec 49 
  
  start_2 50446
  end_2 50478
  Total2 in msec 0
  </code></pre>
  
  <p>What goes wrong ? Why is total2 =0 ? Any help please ? </p>