c++ fork, without wait, defuncts execl
<p>Looking to fork a process, in c++, that wont hang its parent process - its parent is a daemon and must remain running. If i wait() on the forked process the forked execl wont defunt - but - it will also hang the app - not waiting fixes the app hang - but the command becomes defunt.</p>

<pre><code>if((pid = fork()) &lt; 0)
    perror("Error with Fork()");
else if(pid &gt; 0) { 
    //wait here will hang the execl in the parent
    //dont wait will defunt the execl command 
    //---- wait(&amp;pid);
    return "";
} else {
    struct rlimit       rl;
    int                 i;

    if (rl.rlim_max == RLIM_INFINITY)
        rl.rlim_max = 1024;

    for (i = 0; (unsigned) i &lt; rl.rlim_max; i++)
        close(i);

    if(execl("/bin/bash", "/bin/bash", "-c", "whoami", (char*) 0) &lt; 0) perror("execl()");
    exit(0);
}
</code></pre>

<p>How can I fork the execl without a wait(&amp;pid) where execl's command wont defunct? </p>

<p><strong>UPDATE</strong>
Fixed by adding the following before the fork</p>

<pre><code>signal(SIGCHLD, SIG_IGN);
</code></pre>

<p>Still working with my limited skills at a more compatible solution based on the accepted answer. Thanks!</p>
