title: Understanding struct itimerval field tv_usec
body: <p>Hi I'm studying this code:</p>
  
  <pre><code>#include &lt;signal.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  
  volatile sig_atomic_t print_flag = true;
  static int count = 0;
  
  void timer_handler (int signum)
  {
  
   printf ("timer expired %d times\n", ++count);
   if(count&gt;20) {
      print_flag = false;
   } 
  }
  
  int main ()
  {
   struct sigaction sa;
   struct itimerval timer;
  
   /* Install timer_handler as the signal handler for SIGVTALRM. */
   memset (&amp;sa, 0, sizeof (sa));
   sa.sa_handler = &amp;timer_handler;
   sigaction (SIGALRM, &amp;sa, NULL);
  
   /* Configure the timer to expire after 250 msec... */
   timer.it_value.tv_sec = 0;
   timer.it_value.tv_usec = 250000;
   /* ... and every 250 msec after that. */
   timer.it_interval.tv_sec = 0;
   timer.it_interval.tv_usec = 250000;
   /* Start a virtual timer. It counts down whenever this process is
     executing. */
   setitimer (ITIMER_REAL, &amp;timer, NULL);
  
   /* Do busy work. */
   while (print_flag) {
      sleep(1);
   }
  
  printf("job done bye bye\n");
      exit(0);
  
  }
  </code></pre>
  
  <p>With this settings everything goes fine and i get this output</p>
  
  <pre><code>...
  timer expired 17 times
  timer expired 18 times
  timer expired 19 times
  timer expired 20 times
  timer expired 21 times
  job done bye bye
  </code></pre>
  
  <p>If i try to alter the code commenting <code>timer.it_interval.tv_usec</code> and      <code>timer.it_interval.tv_usec</code>and setting both  <code>timer.it_value.tv_sec</code> and <code>timer.it_value.tv_sec</code> equal to, for instance, 3 it doesn't do his job.</p>
  
  <p>However if I maintain an explicit declaration of <code>tv_usec</code> like this it works:</p>
  
  <pre><code> timer.it_value.tv_sec = 3;
   timer.it_value.tv_usec = 0;
   timer.it_interval.tv_sec = 3;
   timer.it_interval.tv_usec = 0;
  </code></pre>
  
  <p>Why I'm bonded on the explicit declaration of <code>tv_usec</code> for both fields?</p>