Search This Blog

Monday, September 28, 2015

Process Creation

import os

def child_process () :
    print "I am the child process and my PID is: %d" %os.getpid()
    print "The child is exiting"


def parent_process():
    print "I am the parent process and my PID is: %d" %os.getpid()
    print "Calling child process"
    childpid = os.fork()

    if childpid == 0:
        #We are inside child
        child_process()
    else:
        #We are inside parent process
        print "We are inside parent process"
        print "The child pid i %d" %childpid

    while True:
        pass

    print "I am still in parent and my PID is: %d" %os.getpid()

parent_process()
   

No comments:

Post a Comment