Created
January 7, 2021 06:54
-
-
Save ShamaUgale/2dd43bc280cc4914fafc17cc943c9b7e to your computer and use it in GitHub Desktop.
Make a python program that creates 1 child process which pushes random integers until the parent terminates to the parent process every 1 second for N seconds, not known until after the child process is created, have the parent read and print the integers, then have the program terminate correctly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import multiprocessing | |
def createChildProcess(sec): | |
q = multiprocessing.Queue() | |
n = os.fork() | |
for i in range(1, sec): | |
if n==0: | |
randomInt =random.randint(1, 99999) | |
print("data: " , randomInt) | |
q.put(randomInt) | |
print("Child id : ", os.getpid()) | |
else: | |
print("getting data in parent process : ", q.get()) | |
createChildProcess(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment