title: How to use fork() in unix? Why not something of the form fork(pointerToFunctionToRun)?
body: <p>I am having some trouble understanding how to use Unix's <code>fork()</code>. I am used to, when in need of parallelization, spawining threads in my application. It's always something of the form</p>
  
  <pre><code>CreateNewThread(MyFunctionToRun());
  
  void myFunctionToRun() { ... }
  </code></pre>
  
  <p>Now, when learning about Unix's <code>fork()</code>, I was given examples of the form:</p>
  
  <pre><code>fork();
  printf("%d\n", 123);
  </code></pre>
  
  <p>in which the code after the fork is "split up". I can't understand how fork() can be useful. Why doesn't fork() have a similar syntax to the above CreateNewThread(), where you pass it the address of a function you want to run?</p>
  
  <p>To accomplish something similar to CreateNewThread(), I'd have to be creative and do something like</p>
  
  <pre><code>//pseudo code
  id = fork();
  
  if (id == 0) { //im the child
      FunctionToRun();
  } else { //im the parent
      wait();
  }
  </code></pre>
  
  <p>Maybe the problem is that I am so used to spawning threads the .NET way that I can't think clearly about this. What am I missing here? What are the advantages of <code>fork()</code> over <code>CreateNewThread()</code>?</p>
  
  <p>PS: I know <code>fork()</code> will spawn a new <strong>process</strong>, while <code>CreateNewThread()</code> will spawn a new <strong>thread</strong>.</p>
  
  <p>Thanks</p>