title: Waiting for system call to finish
body: <p>I've been tasked to create a program that takes a text file that contains a list of programs as input.  It then needs to run valgrind on the programs (one at a time) until valgrind ends or until the program hits a max allotted time.  I have the program doing everything I need it to do EXCEPT it isn't waiting for valgrind to finish.  The code I'm using has this format:</p>
  
  <pre><code>//code up to this point is working properly
  pid_t pid = fork();
  if(pid == 0){
      string s = "sudo valgrind --*options omitted*" + testPath + " &amp;&gt;" + outPath;
      system(s.c_str());
      exit(0);
  }
  //code after here seems to also be working properly
  </code></pre>
  
  <p>I'm running into an issue where the child just calls the system and moves on without waiting for valgrind to finish.  As such I'm guessing that system isn't the right call to use, but I don't know what call I should be making.  Can anyone tell me how to get the child to wait for valgrind to finish?</p>