I am writing a program where multiple child processes can be created and the parent process continues to execute even while the child processes have not been terminated. However, once they are terminated, I want them to be printed before prompting the user to create more child processes.
From my understanding of(waitpid((pid_t)-1, NULL, WNOHANG), it should wait and check for all terminated child processes
- return 0 should there be no terminated processes
- return pid of terminated process
- return -1 for error
does it return multiple return values for each terminated child process?
pid_t temp;
while(waitpid((pid_t)-1, NULL, WNOHANG)){
temp = (waitpid((pid_t)-1, NULL, WNOHANG)
if(temp == -1)
//error code
else if(temp == 0)
break;
else{
//fprintf pid of terminated child process
//this statement never gets executed when I run the code
}
}
(Not looking for code; just want to know if I am understanding the concept properly :-/ Read through man for waitpid)
Thank you!