title: Linux fork() and wait()
body: <p>i have one, bad smelling problem :(</p>
  
  <p>i have this code:</p>
  
  <pre class="lang-c prettyprint-override"><code>int main()
  {
      pid_t child, parent;        
      int status=0;
      int i;
  
      printf("parent = %d\n", getpid());
  
      for(i=1; i&lt;=5; i++){
          if( (child = fork()) == 0){
              sleep(i);
              printf("i=%d, %d\n",i, getpid());
          }
      }
      wait(0);
      while( (parent = wait(&amp;status)) &gt; 0){
          printf("Exit = %d, child = %d\n", status/256, parent);
      }    
  }
  </code></pre>
  
  <p>and output is similar to:</p>
  
  <pre><code>    1, 21320
      2, 21321
      Exit = 0, child = 21321
      3, 21322
      Exit = 0, child = 21322
      4, 21323
      Exit = 0, child = 21323
      5, 21324
      Exit = 0, child = 21324
  </code></pre>
  
  <p>And i think that wait(0) not waiting for all subprocess but only wait for first exit and write all (Exit = ...).</p>
  
  <p>Is any way to do this:</p>
  
  <pre><code>    1, 21320
      2, 21321
      3, 21322
      4, 21323
      5, 21324
  
      Exit = 0, child = 21320
      Exit = 0, child = 21321
      Exit = 0, child = 21322
      Exit = 0, child = 21323
      Exit = 0, child = 21324
  </code></pre>
  
  <p>?</p>