title: process catch SIGINT signal using sigint_handler
body: <p>I encountered this problem when doing shell lab from the book CSAPP, the lab ask you to implement your own version of shell with some specification,one of them is </p>
  
  <blockquote>
    <p>Typing ctrl-c (ctrl-z) should cause a SIGINT (SIGTSTP) signal to be
    sent to the current foreground job, as well as any descendents of that
    job (e.g., any child processes that it forked). If there is no
    foreground job, then the signal should have no effect.</p>
  </blockquote>
  
  <p>so you should complete one of the given functions called sigint_handler which supposed to catch SIGINT signal and send it along to the foreground job. below is a piece of code I find online(the code passed the correctness check)</p>
  
  <pre><code>void sigint_handler(int sig) 
  {
      int olderrno = errno;
      pid_t pid = fgpid(jobs);
      if (pid != 0)
          kill(-pid, sig);
      errno = olderrno;
      return;
  }
  </code></pre>
  
  <p>what I don't understand is if SIGINT is sent using kill,then the descendents of foreground job will also use this   handler to catch SIGINT signal right? so it's  kind of a recursive call to me.so how does this actually work? thanks for helping me.</p>
  
  <p>handler is installed in the main function</p>
  
  <pre><code>signal(SIGINT,  sigint_handler);   /* ctrl-c */
  </code></pre>
  
  <p>and fgpid return PID of current foreground job, 0 if no such job</p>