title: Receiving SIGINT and exception Handles in Linux
body: <p>Let's say we have a program in C that uses the sleep() function</p>
  
  <p>The program executes and goes to sleep. Then we type <kbd>Ctrl</kbd>+<kbd>C</kbd> to send a SIGINT signal to the process.</p>
  
  <p>We know that the default action upon receipt of a SIGINT is to terminate the process, we also know that the sleep() function resume the process whenever the sleeping process receives a signal.</p>
  
  <p>And my textbook says in order to allow sleep() function to return, we must install a SIGINT handler like this:</p>
  
  <pre><code>void handler(int sig){
      return; /* Catch the signal and return */
  }
  ...
  int main(int argc, char **argv) {
     ...
     if (signal(SIGINT, handler) == SIG_ERR) /* Install SIGINT handler */
        unix_error("signal error\n");
     ...
     sleep(1000)
  }
  </code></pre>
  
  <p>Althouth the code seems to be straightforward, I still have questions if I want to dig deeper:</p>
  
  <p>Background: When the process is sleeping and we type <kbd>Ctrl</kbd>+<kbd>C</kbd> to send SIGINT</p>
  
  <p>Q1-My understanding is, Kernel sends SIGINT to the process by updating the SIGINT's corresponging pending bit in the pend bit vector, is my understanding correct?</p>
  
  <p>Q2-The processor detects the existance of SIGINT, but since we overwrite the handler to make it return in stead of terminating the process, so our handler get executed, and then Kernel clears SIGINT's corresponging pending bit, is my understanding correct?</p>
  
  <p>Q3- Since SIGINT's corresponging pending bit is cleared, then how can sleep() function gets return? I think it should be in sleep still because in theory, sleep() function has no way of knowing the existance of SIGINT(has been cleared)</p>