
# import module os.
import os
import time
id = os.fork()

if (id==0):
# this is the first child
        parent = os.getppid()
	for k in range(7):
		time.sleep(1)
		cid=os.getppid()
		print "First Child: My parent is process ID ", cid
		if (parent <> cid):
			print "I just became an orphan"
			parent=cid
else:
	nid = os.fork()
	if(nid):
		time.sleep(3)
		print 'Parent Waiting for Second child to finish'
		os.waitpid(nid,0)
		print 'Second Child just finished'
		print 'Parent Waiting for First child to finish'
		os.waitpid(id,0)
		print 'First Child just finished: Parent now exiting'


