[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
Post a Comment