title: set jump and long jump codeflow in c
body: <p>I am trying to learn setjump and longjump in C. Can anyone help me with the output of the following code along with the code flow and the explanation for the the cases.i have called a function funcall() in the code. The alarm is being called for the first iteration but in the subsequent iterations the alarm is not being called. Why is it so? Does alarm(0) prevents any future alarm requests?</p>
  
  <p>EDIT : Even after deleting the "print_T()" line in the signal handler the code doesnot seem to run.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;setjmp.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;time.h&gt;
  
  #define LEN 50
  
  jmp_buf po;
  
  void print_T() {
      time_t rawtime;
      struct tm * timeinfo;
  
      time(&amp;rawtime);
      timeinfo = localtime ( &amp;rawtime );
      printf ( "Current local time and date: %s", asctime (timeinfo) );
  }
  
  
  
  static void ti() {
      print_T();
      longjmp(po,1);
  }
  int funcall(int reply) {
  
  
      static int p;
      p = 0;
      signal(SIGALRM, ti);
      int q = setjmp(po);
      if(q == 0)  
          printf("the value BEFORE setjmp %d for reply %d\n", p, reply);
      else 
          printf("the value AFTER setjmp %d for reply %d\n", p, reply);
      alarm(5);
  
      if(p &gt; 0) {
          printf("INVOKING THE ALARM");
          alarm(0);
          return -1;
      }
  
      p++;    
      for(int i = 0; i &lt; 100000; i++) 
          for(int j = 0; j &lt; 100000; j++);
      return 0;
  
  }
  
  int main() {
  
      int a;
      int reply;
      time_t start, end;
      for(reply=0; ; reply++) {
          printf("~~~~~~~~~~~~~~~~~~~~~~~~~ITERATION NUMBER  %d\n", reply);
  
          time(&amp;start);
          a = funcall(reply);
          time(&amp;end);
          double tin = difftime(end, start);
          printf("*********************ITERATION END  and a returned is %d after %f\n", a, tin );
          double tidiff = difftime(end, start);
          if(a &lt; 0)
              if(reply == 10) {
                  break;
             }
  
      }
  
  }
  </code></pre>