title: getutent and Linux timer issues
body: <p>I have a problem running the below code , which invokes getutent() to count the total number of users currently logged in to the system. The timer will be invoked every 1sec and will set the boolean named "isSigAlrmOccured" to true and exit.The main function checks whether the timer signal is delivered by checking this boolen and monitor the number of loggedin users. Unfortunately, the timer signal is delivered to the main program only two times correctly and I don't get any further signals after that. The pause function call doesn't get interrupted after the first two signals.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;utmp.h&gt;
  #include &lt;errno.h&gt;
  
  static int isSigAlrmOccured;
  
  void alarm_handler (int signo)
  {
    static int i=1;
    printf("\n Signal Occurred %d times\n",i++);
    isSigAlrmOccured = 1;
  
  }
  
  int main (int argc, char *argv[]) {
     struct itimerval delay;
     struct utmp *utmpstruct;
     int numuser;
  
  
     int ret;
     signal (SIGALRM, alarm_handler);
     delay.it_value.tv_sec = 1;
     delay.it_value.tv_usec = 0;
     delay.it_interval.tv_sec = 1;
     delay.it_interval.tv_usec = 0;
     ret = setitimer (ITIMER_REAL, &amp;delay, NULL);
     if (ret) {
       perror ("setitimer");
       return 0;
     }
     for (;;) {
         pause ( );
         /* count the number of users */
         if ( (errno == EINTR) &amp;&amp; (isSigAlrmOccured) ) {
             isSigAlrmOccured = 0;
             setutent();
             while ((utmpstruct = getutent())) {
             if ((utmpstruct-&gt;ut_type == USER_PROCESS) &amp;&amp;
                 (utmpstruct-&gt;ut_name[0] != '\0'))
                 numuser++;
             }
             endutent();
         }
     }
     return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p>Signal Occurred 1 times</p>
  
  <p>Signal Occurred 2 times
  </p>