title: Stuck on wait() after fork()
body: <p>I have looked on some topics about this, but could not solve it -</p>
  
  <p>I am forking twice, but when waiting for the last proc it get stuck on wait(), if i remove the wait() it moves on, but obviously it does not wait:</p>
  
  <p>here is the relevant code:</p>
  
  <pre><code>  /*Fork #1*/
    if((pid=fork())==0)
    {
      if(command -&gt; inputRedirect != NULL)
      {
        fclose(stdin);
        fopen(command -&gt; inputRedirect,"r");
      }
      fclose(stdout);
      dup(pipefd[1]);
      close(pipefd[1]);
      i=execvp(command-&gt;arguments[0],command-&gt;arguments);
    }
    if(i == -1)
    {
      perror("Error");
      return 1;
    }
    printf("\nParent: %d , Child: %d\n",getpid(),pid);
  
    command = command-&gt;next;
    /*Fork #2*/
    if((pid=fork())==0)
    {
  
      fclose(stdin);
      dup(pipefd[0]);
      close(pipefd[0]);
  
      if(command -&gt; outputRedirect != NULL)
      {
        fclose(stdout);
        fopen(command -&gt;outputRedirect,"w");
      }
  
      i=execvp(command-&gt;arguments[0],command-&gt;arguments);
      _exit(0);
    }
  
    if(i == -1)
    {
      perror("Error");
      return 1;
    }
  
    if(command-&gt;blocking == 1)
    {
      int test=0;
      printf("\nParent: %d , Child: %d\n",getpid(),pid);
      printf("\ntest1\n");
      while((test=wait(NULL)) != pid)
      {
        printf("\n %d \n ", test);
      }
      printf("\ntest2\n");
    }
    return 0;
  }
  </code></pre>
  
  <p>i added some tests to see some PID outputs and whats going on inside, it waits for the first chil process to finish, and print the right ID, but on the second one it just blocks.</p>
  
  <p>I do however see on screen that the second process finished (from the process output).</p>
  
  <p>Any help on the topic would be most welcome.</p>
  
  <p>thank you.</p>