title: SIGTSTP signal not stopping child?
body: <p>I'm trying to write a program that forks, the child executes a command and then returns control to the parent. I am having trouble getting the SIGTSTP (C-z) signal to work as intended, though... I want the parent to ignore it, but the child to stop and return control to the parent, so that the child can later be resumed or killed (with a builtin command). I isolated the relevant code into a smaller program just to test it, and it seems like A) the child doesn't stop when C-z is typed, or B) it does stop, but does not return control to the parent (I'm leaning towards this because when I use cat for stdin, it behaves differently after the C-z). Here is my code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;cstring&gt;
  #include &lt;unistd.h&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;signal.h&gt;
  
  
  int main(){
    std::cout.setf(std::ios::unitbuf);
  
    std::vector&lt;std::string&gt; vec; vec.push_back("cat");
    std::vector&lt;char*&gt; chvec;
    for(unsigned int i = 0; i &lt; vec.size(); i++){
      chvec.push_back(&amp;vec[i][0]);
    }
    chvec.push_back(NULL);
    vec.erase(vec.begin(), vec.begin() + chvec.size());
  
    char** argv = &amp;chvec[0];
    signal(SIGTSTP,SIG_IGN);
  
    pid_t pid;
    if((pid = fork()) == 0){
      signal(SIGTSTP,SIG_DFL);
      /*pid = getpid();
      setpgid(pid,pid);*/
      std::cout &lt;&lt; "before exec" &lt;&lt; std::endl;
      execvp(argv[0],argv);
      perror("exec");
    }
    else{
      //setpgid(pid,pid);
      int status;
      waitpid(pid,&amp;status,0);
      if(WIFEXITED(status) || WIFSIGNALED(status)){
        std::cout &lt;&lt; "exited or signaled" &lt;&lt; std::endl;
      }
      if(WIFSTOPPED(status)){
        std::cout &lt;&lt; "process stopped" &lt;&lt; std::endl;
      }
      //std::cout &lt;&lt; "process exited" &lt;&lt; std::endl;
      pause();
    }
    return EXIT_SUCCESS;
  }
  </code></pre>