title: Regarding The os.fork() Function In Python
body: <p>I'm just beginning with python and I developed a simple program to fork a parent process. Here's the code I've written so far...</p>
  
  <pre><code>#!/usr/bin/env python
  import os
  
  def child():
      print "We are in the child process with PID= %d"%os.getpid()
  
  def parent():
      print "We are in the parent process with PID= %d"%os.getpid()
      newRef=os.fork()
      if newRef==0:
          child()
      else:
          print "We are in the parent process and our child process has PID= %d"%newRef
  
  parent()
  </code></pre>
  
  <p>From what I understand, the code should begin by calling the parent process and display its PID. Afterwards, the <code>os.fork()</code> is called and it creates a copy of the parent process, and since we are already in the parent process, the <code>newRef</code> variable should contain a value that is positive and the <code>else</code> part of my code is the one that should be executed. My question is that: why did the code initiate to call the <code>child()</code> function afterwards although the <code>if</code> part of my code should not execute.</p>
  
  <p>Thanks in advance :)</p>