title: Getting the wrong return code from exit() after fork() and wait()
body: <p>I'm working on unit tests for my little daemon but I'm having trouble getting the right exit code from the forked process. If I only run one of the testcases they work fine, but if I run two in a row the second one fail since it doesn't get EXIT_SUCCESS as a return code. I've checked and the second test case does call exit(EXIT_SUCCESS) so it should return that, but somehow I get another child process. </p>
  
  <p>What am I missing?</p>
  
  <pre><code>bool test_setup() {
      pid_t pid = fork();
      if(pid &lt; 0) {
          fail("Failed to fork", PLACE);
      }
      else if(pid &gt; 0) { //main thread
          //act as client to server, this code might call exit(EXIT_FAILURE)
          exit(EXIT_SUCCESS);
      }
      //child thread
      //run server
      int retval; //return value from child process
      wait(&amp;retval);
      return WEXITSTATUS(retval) == EXIT_SUCCESS;
  }
  
  bool test_send_one() {
      pid_t pid = fork();
      if(pid &lt; 0) {
          fail("Failed to fork", PLACE);
      }
      else if(pid &gt; 0) { //main thread
          //act as client to server, this code might call exit(EXIT_FAILURE)
          cout &lt;&lt;"exit success" &lt;&lt;endl;
          exit(EXIT_SUCCESS);
      }
      //child thread
      //run server
      int retval; //return value from child process
      wait(&amp;retval);
      return WEXITSTATUS(retval) == EXIT_SUCCESS;
  }
  
  int main(int argc, char** argv) {
      test_setup();   
      test_send_one();
  }
  </code></pre>