int main()
{
...
if(!fork())
{
execvp(cmdName,cmdParam);
}
printf("In main()...");
return(0);
}
- Assuming I have correctly passed the cmdName & cmdParam arguments, how do I wait for the process created by execvp to finish, before resuming the execution of main()?
- Does the execvp() create a process which is a child of the newly fork()ed process?
In the parent process,
forkreturns the PID of the child process, so you can store that in a variable, and then usewaitpidto wait for the child process to terminate.Not really – the new child process created by
forkis a duplicate of the parent, andexecvpthen replaces its process image with a new image. Effectively you initially have two ‘copies’ of the parent, one of which then ‘becomes’ the new program.