title: How does (waitpid((pid_t)-1, NULL, WNOHANG) keep track of child processes to be returned?
body: <p>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.</p>
  
  <p>From my understanding of(waitpid((pid_t)-1, NULL, WNOHANG), it should wait and check for all terminated child processes </p>
  
  <ul>
  <li>return 0 should there be no terminated processes</li>
  <li>return pid of terminated process </li>
  <li>return -1 for error</li>
  </ul>
  
  <p>does it return multiple return values for each terminated child process?</p>
  
  <pre><code>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 
       }
  }
  </code></pre>
  
  <p>(Not looking for code; just want to know if I am understanding the concept properly :-/ Read through man for waitpid)</p>
  
  <p>Thank you!</p>