title: Why SIGALRM triggers semaphore?
body: <p>I am a new man in linux programming. I did the following experiment and found a curious phenomenon: I set a timer in the program, when it times out, it triggers the semaphore, but I didn't use the function &quot;sem_post&quot; in the timer_handler. Can anyone explain the reason? How can I block the SIGALRM in semaphore? Thank you.
  The following is my code:</p>
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;semaphore.h&gt;
  #include &lt;signal.h&gt;
  
  int count = 1;
  sem_t job_queue;
  
  void timer_handler(int signum)
  {
      printf(&quot;time out...\n&quot;);
  }
  
  void init_timer_signal_action()
  {
      struct sigaction timer_act;
      timer_act.sa_handler = timer_handler;
      timer_act.sa_flags  = 0;
  
      sigemptyset(&amp;timer_act.sa_mask);
      sigaction(SIGALRM, &amp;timer_act, NULL);
  }
  
  void init_timer()
  {
      struct itimerval value;
      value.it_value.tv_sec=5;
      value.it_value.tv_usec=0;
      value.it_interval=value.it_value;
      setitimer(ITIMER_REAL,&amp;value,NULL);
  }
  
  int main(void)
  {
      init_timer_signal_action();
      init_timer();
  
      sem_init(&amp;job_queue, 0, 0);
  
      while(1)
      {
          sem_wait(&amp;job_queue);
          printf(&quot;Now count is: %d.\n&quot;, count++);
      }
  
      sem_destroy(&amp;job_queue_count);
      return 0;
  }
  </code></pre>
  <p>The following is the results of running the program:
  time out...
  Now count is: 1.
  time out...
  Now count is: 2.
  time out...
  Now count is: 3.
  time out...
  Now count is: 4.
  time out...
  Now count is: 5.</p>