Return from the parent process code or common code In this program, the parent process creates a child process, then the child executes ls -l. The parent process waits for the child process to complete and then returns using return 0;. 

/*child's output redirected to file*/
/*sps, 6262015*/

/*Headers*/
#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;unistd.h&gt;
#include&lt;sys/wait.h&gt;
#include&lt;sys/types.h&gt;

/*Start*/
int main(void)
{
    //Create a child process
    int ret = fork();
    if(ret&lt;0)
            exit(1);
    /*Child code*/
    else if(ret==0)
    {
            char *argv[] = {"ls", "-l", NULL};

            //Execute 'ls -l'
            execvp(argv[0], argv);
    }
    /*Parent code*/
    else if(ret&gt;0)
    {
            int status;
            int w = waitpid(ret, &amp;status, WUNTRACED | WCONTINUED);
    }
    /*Where to place this ???*/
    return 0;
}


Although above code works correctly, I am not sure where to place the return 0; statement. For instance, in the above code it is at the end so it is common to both the parent and child processes.

But in this program, the child process calls execvp, so it will never reach the last line of the code which has return 0;. So, taking this into account, can I place the return 0; inside the parent code as below?

 /*Parent code*/
 else if(ret&gt;0)
 {
         int status;
         int w = waitpid(ret, &amp;status, WUNTRACED | WCONTINUED);
         return 0;
 }


Is there any advantage or disadvantage to putting the return 0; statement inside the parent process code?
As for all these functions:  Take a look at the man page.  It states
that execvp (respectively execve) will return on error with return
value -1 and with errno set.

Since you are already handling such errors with fork you might as
well do it here and either exit(1), or fall through to the end.