First page Back Continue Last page Overview Graphics

Forking with counters

import os, time

def counter(count):

for i in range(count):

time.sleep(1)

print('%s. count of [%s]' % (i, os.getpid()))

for i in range(3):

pid = os.fork()

if pid == 0:

counter(4)

os._exit(0)

else:

print('Another process spawned: %d' % pid)

print('Exit of parent process')