title: sigaction catching SIGALRM
body: <p>My goal is to make an alarm that goes off every second so that when it is handled by sigaction it prints the time, so each second the new time is printed. I have a loop in the middle of this code that counts to a random number but I took that out to make this code more condensed and easier to look at because I believe the problem is with how I'm using sigaction, because it prints multiple times for one second but I just need one line of output for this second.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;time.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  void alarmPrint(int signum);
  
  time_t curtime;
  
  int main(){
  
    printf("Enter ^C to end the program:\n");
  
    struct sigaction sig;
  
    sig.sa_handler = alarmPrint;
  
    int count;
  
    int final;
  
    time(&amp;curtime);
  
    srandom(curtime);
  
    while(1){
  
      time(&amp;curtime);
  
      alarm(1);
  
      printf("\n");
  
      if(sigaction(SIGALRM, &amp;sig, 0) == -1){
  
        printf("Error\n");
  
      }
  
    }
  
    return 0;
  
  }
  
  
  void alarmPrint(int signum){
  
    printf("current time is %s\n", ctime(&amp;curtime));
  
  }
  </code></pre>