title: need programs that illustrate use of settimer and alarm functions in GNU C
body: <p>Can anyone illustrate the use of settimer or alarm function in gnu C , with some <strong>program examples</strong> ,please ?</p>
  
  <p>I have a program that continuously processes some data , and i need to set a timer / alarm that goes off every t seconds , in response to which , i need to store the processed data into a file. This file writing has to be asynchronous &lt; i.e. the data processing and file writing must not wait for each other > . I went through the GNU C Library pages , but i couldn't understand much..</p>
  
  <p>[EDIT]</p>
  
  <p>I got this program :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;sys/time.h&gt;
  
  #define INTERVAL 1
  
  int howmany = 0;
  
  void alarm_wakeup (int i)
  {
     struct itimerval tout_val;
  
     signal(SIGALRM,alarm_wakeup);
  
     howmany += INTERVAL;
  
     printf("\n%d sec up partner, Wakeup!!!\n",howmany);
     tout_val.it_interval.tv_sec = 0;
     tout_val.it_interval.tv_usec = 0;
     tout_val.it_value.tv_sec = INTERVAL; /* 10 seconds timer */
     tout_val.it_value.tv_usec = 0;
  
     setitimer(ITIMER_REAL, &amp;tout_val,0);
  
  }
  
  void exit_func (int i)
  {
      signal(SIGINT,exit_func);
      printf("\nBye Bye!!!\n");
      exit(0);
  }
  
  int main ()
  {
    struct itimerval tout_val;
  
    tout_val.it_interval.tv_sec = 0;
    tout_val.it_interval.tv_usec = 0;
    tout_val.it_value.tv_sec = INTERVAL; /* 10 seconds timer */
    tout_val.it_value.tv_usec = 0;
    setitimer(ITIMER_REAL, &amp;tout_val,0);
  
    signal(SIGALRM,alarm_wakeup); /* set the Alarm signal capture */
    signal(SIGINT,exit_func);
  
    while (1)
    {
      //printf("!");
    }
  
    return 0;
  
  }
  </code></pre>
  
  <p>But seems like i cannot do anything while the timer is on..
  What should i modify to suit my needs ? Pl suggest..
  [/EDIT]</p>