title: Trying to create multiple processes in C++ using fork(); doesn't appear to be working
body: <p>I'm trying to create a parent process with multiple child processes using fork() in C++. I tried using the code from <a href="https://stackoverflow.com/questions/876605/multiple-child-process">this question</a> to create a simple program that would have each process count upwards; the parent would print "I am process 0", the first child "I am process 1", and so on.</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;fstream&gt;
  #include &lt;sys/wait.h&gt;
  using namespace std;
  
  const int PROCESSES = 5;
  void Printer(int psno);
  int iAmProcess = 0;
  
  int main()
  {
  
      int pids[PROCESSES];
  
      Printer(iAmProcess);
  
      for (int j = 0; j &lt; PROCESSES; j++)
      {
          if (pids[j] = fork() &lt; 0)
          {
              perror("Error in forking.\n");
              exit(EXIT_FAILURE);
          }
          else if (pids[j] == 0)
          {
              Printer(iAmProcess);
              exit(0);
          }
      }
  
      int status;
      int pid;
      int n = PROCESSES;
      while (n &gt; 0)
      {
          pid= wait(&amp;status);
          --n;
      }
      return 0;
  }
  
  void Printer(int psno)
  {
      printf("I am process %d\n", psno);
  }
  </code></pre>
  
  <p>Instead of the expected output:</p>
  
  <pre><code>I am process 0
  I am process 1
  I am process 2
  I am process 3
  I am process 4
  I am process 5
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>I am process 0
  I am process 0
  I am process 0
  I am process 0
  </code></pre>
  
  <p>And then the program terminates. What am I doing wrong?</p>