title: calling signal after fork
body: <p>Is there any difference between "code listing 1" and "code listing 2"? Because in Code Listing 1, the child process is able to catch the SIGTERM signal and exit nicely. But code listng 2 is terminating abruptly on SIGTERM signal.</p>
  
  <p>I am using Linux and C.</p>
  
  <p><strong>Code Listing 1</strong></p>
  
  <pre><code>if (signal(SIGTERM, stopChild) == SIG_ERR) {
      printf("Could not attach signal handler\n");
      return EXIT_FAILURE;
  }
  pid = fork();
  </code></pre>
  
  <p><strong>Code Listing 2</strong>    </p>
  
  <pre><code>pid = fork();
  if (signal(SIGTERM, stopChild) == SIG_ERR) {
      printf("Could not attach signal handler\n");
      return EXIT_FAILURE;
  }
  </code></pre>
  
  <p>The strange part is that <strong>in Code Listing 2, both child and parent process sets the signal handler for SIGTERM</strong>. So, this is supposed to work. Isn't it?</p>