title: To perform a task when timer is running
body: <p>Please help me, i have created a timer and I want to perform a specific task when my timer is running. but my code is not allowing me to run the task when timer is running. It only sleeps when timer is running. my code is </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;sys/time.h&gt;
  #include&lt;signal.h&gt;
  #include &lt;time.h&gt;
  #define INTERVAL 10
  
  
  void timerhandler(int signum)
  {
  
  printf("\ni m manoj doing some specila task\n");
  
  }
  
  int timer()
  {
      int i;
      struct itimerval val;
      struct sigaction action;
  
      sigemptyset(&amp;action.sa_mask);
      action.sa_handler=&amp;timerhandler;
      action.sa_flags=SA_RESTART;
      if(sigaction(SIGALRM,&amp;action,NULL)==-1)
      {   
          perror("sigaction");
          return 1;
      }
  
  
      val.it_interval.tv_sec  = 0;
      val.it_interval.tv_usec = 0;
      val.it_value.tv_sec = 3;
      val.it_value.tv_usec    = 0;
  
      if(setitimer(ITIMER_REAL,&amp;val,0)==-1)
  
          perror("alarm");
  
  
  
      else 
  
      for(;;)
      {
      Sleep(10);
      printf("timer val is  %d", &amp;val.it_value.tv_sec );
      printf("\ni m manoj doing normal task\n");
  
      return 0;
      }
      return 0;
  }
  
  int main()
  {
  timer();
  }
  </code></pre>