title: Can a C program continue execution after a signal is handled?
body: <p>I'm new at signal handling in Unix through C and I have been looking at some tutorials on it (out of pure interest).</p>
  
  <p>My questions is, is it possible to continue execution of a program past the point where a signal is handled?</p>
  
  <p>I understand that the signal handling function does the cleanup but in the spirit of exception handling (such as in C++), is it possible for that signal to be handled in the same fashion and for the program to continue running normally?</p>
  
  <p>At the moment <code>catch</code> goes in an infinite loop (presumably a way to quit would be to call <code>exit(1)</code> ). </p>
  
  <p>My intention would be for <code>b</code> to be assigned 1 and for the program to finish gracefully (if that is possible of course).</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;signal.h&gt;
  #include &lt;stdio.h&gt;
  
  int a = 5;
  int b = 0;
  
  void catch(int sig)
  {
      printf("Caught the signal, will handle it now\n");
      b = 1;
  }
  
  int main(void)
  {
      signal(SIGFPE, catch);
  
      int c = a / b;
  
      return 0;
  }
  </code></pre>
  
  <p>Also, as C is procedural, how come the signal handler declared before the offending statement is actually called after the latter has executed?</p>
  
  <p>And finally, in order for the handling function to do its clean up properly, all the variables than need to be cleaned up in the event of an exception need to be declared prior to the function, right?</p>
  
  <p>Thanks in advance for your answers and apologies if some of the above is very obvious.</p>