title: How to fork() an exact number of children
body: <p>So I'm working on a program that will do a certain task multiple times.  I've written the program once already using threads, but now I'm required to do it using processes with fork().  </p>
  
  <p>With threads, I'd simply create the specified number of threads, have them execute a function (changing a variable in shared memory), and then finally execute something that used the final value in shared memory.</p>
  
  <p>Now however I want to do the same thing but I'm not sure how to do it as everytime I call fork() it essentially doubles itself.  So obviously if I call fork() in a forloop, each parent and child process will then go through the loop calling fork() on their own.</p>
  
  <p>So my question in a nutshell:
  how could I create an exact number of child processes using fork (lets say I need 5 children), and have my parent process wait until these 5 are done executing before it moves on?</p>
  
  <p>Thanks for the help!</p>