So basically what i need is:
pid = fork();
if (pid == -1)
exit(1);
if (pid == 0)
{
// do stuff in child
}
else
{
// ONLY do stuff while child is running
}
would I need to create a tmp file right before the child exits saying that it is no longer running so the parent knows the child has exited when that file exists, or is there a simpler way to do this?
You can use
waitpidto know if a child process is still running:With
WNOHANG,waitpidreturns immediately so that the program can do something else.When you have nothing to do other than waiting for the child process to terminate, call
waitpidwithoutWNOHANG.