title: Sending signals between parent and child process in c
body: <p>I'm trying to write a program that sends signals between a parent and child process.
  This is what I have so far:</p>
  
  <pre><code>void parent_sig(int signo){
      if(signo == SIGINT){
          printf("*** Parent received SIGINT ***\n");
      }else if(signo == SIGTSTP){
          //first time
          signal(SIGUSR1, c_sig_usr);
  
          //second time
          printf("*** Parent received SIGTSTP ***\n");
          exit(0);
  
      }else if(signo == SIGUSR1){
          printf("*** Parent received SIGUSR1 ***\n");
          sleep(3);
          signal(SIGUSR1, c_sig_usr); 
      }else{
              pause();
      }
  
  }
  
  void child_sig(int signo){
      if(signo == SIGINT){
          printf("*** Child received SIGINT ***\n");
      }else if(signo == SIGTSTP){
          printf("*** Child received SIGTSTP ***\n");
      }else if(signo == SIGUSR1){
          printf("*** Child received SIGUSR1 ***\n");
          sleep(3);
          signal(SIGUSR1, p_sig_usr); 
      }else{
          pause();
      }
  }
  
  int main(void)
  {
      pid_t child, parent;
      parent = getpid();
  
      struct sigaction p_sig;
      p_sig.sa_handler = &amp;parent_sig;
  
  
      if((child = fork()) &lt; 0) { 
          perror("**ERROR**: failed to fork process"); 
          exit(EXIT_FAILURE); 
      }else if (child == 0){
          struct sigaction c_sig;
          c_sig.sa_handler = &amp;child_sig;
      }else{
  
      }
  
  
      return 0;
  }
  </code></pre>
  
  <p>I want it to</p>
  
  <ul>
  <li>create a child process using fork()</li>
  <li>If the SIGINT signal is received, print a message but not exit</li>
  <li>If the SIGTSTP signal is received, the first time send the SIGUSR1 signal to the child process and the second time print a message and exit</li>
  <li>If the SIGUSR1 signal is received, send SIGUSR1 to opposing process</li>
  <li>else both processes wait for a signal to be received</li>
  </ul>
  
  <p>What do I need to change/add to this code to make it work correctly?</p>