If you fork() and exec() from the child process, and wait in the parent, how does the parent get a return code from the child?
<p>I'm learning about <code>fork()</code>, <code>exec()</code>, etc. and I ran into something in a textbook that I don't fully understand.</p>

<p>In the example, a process calls <code>fork()</code>.</p>

<p>In the child process, we call <code>exec()</code>.</p>

<p>Later, in the parent, we call <code>wait()</code>.</p>

<p>It is my understanding that a successful <code>exec()</code> call never returns. If we called <code>exec()</code> in the child, how can we wait for the child to return in the parent, if the child will never have control returned to it from the <code>exec()</code>? </p>

<p>My only guess here is that what happens is the parent, thinking it's waiting on the child, is actually waiting on the new process created with exec? I.e. normally I'd <code>fork()</code> and wait for the child. If I <code>fork()</code> and exec the UNIX program <code>date</code> then wait for the child in the parent, am I actually now waiting for <code>date</code> to exit?</p>

<p>Thanks!</p>