title: How to redirect signal to child process from parent process?
body: <p>I am trying to understand processes in C. I currently want to create shell-like structure which - after pressing a shortcut like <kbd>Ctrl</kbd>+<kbd>C</kbd> or <kbd>Ctrl</kbd>+<kbd>Z</kbd> will kill all its subprocesses but will stay alive. My code looks like this:</p>
  
  <pre><code>#include &lt;ctype.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;readline/readline.h&gt;
  #include &lt;readline/history.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;termios.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;dirent.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;sys/signal.h&gt;
  
  pid_t pid;
  
  void send_signal(int signum){
    kill(pid, signum);
  }
  
  void init_signals(){
    signal(SIGINT, send_signal);
    signal(SIGTSTP, send_signal);
  }
  
  int main(){
      init_signals();
      pid = fork();
    if(pid &gt; 0){
      //Parent Process
      wait(NULL);
    } else {
      // Child Process
      while(1){
          usleep(300000);
      }   
  
    }
  
    return 0;
  }
  </code></pre>
  
  <p>Problem here is that, when I press Ctrl+C, parent redirects it to child and kills it but when I press Ctrl+Z (even though child process is stopped) parent still hangs on <code>wait(NULL)</code>. Any suggestions on how to fix this?</p>