title: sending signal from parent to child
body: <p>I am using this tutorial from website <a href="http://www.code2learn.com/2011/01/signal-program-using-parent-child.html" rel="noreferrer">http://www.code2learn.com/2011/01/signal-program-using-parent-child.html</a> and trying to understand why signal is not recieved by child?</p>
  
  <p>here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;  
  #include &lt;signal.h&gt;
  #include &lt;stdlib.h&gt;  
  void sighup(); /* routines child will call upon sigtrap */  
  void sigint();  
  void sigquit();  
  void main()  
  { int pid;  
      /* get child process */  
      if ((pid = fork()) &lt; 0) {  
          perror("fork");  
          exit(1);  
      }  
      if (pid == 0)  
      { /* child */  
          signal(SIGHUP,sighup); /* set function calls */  
          signal(SIGINT,sigint);  
          signal(SIGQUIT, sigquit);  
          for(;;); /* loop for ever */  
      }  
      else /* parent */  
      { /* pid hold id of child */  
          printf("\nPARENT: sending SIGHUP\n\n");  
          kill(pid,SIGHUP);  
          sleep(3); /* pause for 3 secs */  
          printf("\nPARENT: sending SIGINT\n\n");  
          kill(pid,SIGINT);  
          sleep(3); /* pause for 3 secs */  
          printf("\nPARENT: sending SIGQUIT\n\n");  
          kill(pid,SIGQUIT);  
          sleep(3);  
      }  
  }  
  void sighup()  
  { signal(SIGHUP,sighup); /* reset signal */  
      printf("CHILD: I have received a SIGHUP\n");  
  }  
  void sigint()  
  { signal(SIGINT,sigint); /* reset signal */  
      printf("CHILD: I have received a SIGINT\n");  
  }  
  void sigquit()  
  { printf("My DADDY has Killed me!!!\n");  
      exit(0);  
  }  
  </code></pre>
  
  <p>output:</p>
  
  <p><img src="https://i.stack.imgur.com/zEeHr.png" alt="enter image description here"></p>