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...
#!/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()
From what I understand, the code should begin by calling the parent process and display its PID. Afterwards, the os.fork() is called and it creates a copy of the parent process, and since we are already in the parent process, the newRef variable should contain a value that is positive and the else part of my code is the one that should be executed. My question is that: why did the code initiate to call the child() function afterwards although the if part of my code should not execute.
Thanks in advance :)