[Level 2] How to fork in Python.

#!/usr/bin/env python
import os
import time

def my_fork():
    child_pid = os.fork()
    if child_pid == 0:
        print "Child Process: PID# %s" % os.getpid()
        time.sleep(10) 
    else:
        print "Parent Process: PID# %s" % os.getpid()
        time.sleep(1) 

if __name__ == "__main__":
    my_fork()
$ python /testFork.py
Parent Process: PID# 2292
Child Process: PID# 2293
$
Wish this helps.

regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 1] Rar tool for Solaris.

[Level 2] iif in Python