title: how to correctly wait for execve to finish?
body: <p>A C source code (compiled and running Linux Centos 6.3) has the line:</p>
  
  <pre><code>execve(cmd, argv, envp);
  </code></pre>
  
  <p><code>execve</code> does not return, but I want to modify the code to know when it is finished.  So I do this:</p>
  
  <pre><code>if (child = fork()) {
      waitpid(child, NULL, 0);
      /*now I know execve is finished*/
      exit(0);
  }
  
  execve(cmd, argv, envp);
  </code></pre>
  
  <p>When I do this, the resulting program works 99% of the time, but very rarely it exhibits strange errors.  </p>
  
  <p>Is anything wrong with the above??  I expect the above code to run precisely (except a little slower) as before.  Am I correct?</p>
  
  <p>If you want to know the background, the modified code is <code>dash</code>.  The <code>execve</code> call is used to run a simple command, after <code>dash</code> has figured out the string to run.  When I modify precisely as above (without even running anything after waiting) and recompile and run programs under the modified dash, most of the time they run fine.  However, a recompilation of one particular kernel module called "biosutility" gives me this error</p>
  
  <pre><code>cc1: error: unrecognized command line option "-mfentry"
  </code></pre>