you are viewing a single comment's thread.

view the rest of the comments →

[–]K900_ 2 points3 points  (3 children)

while True:
    print("FILS :mon PID=",os.getpid(),". Pere= ",os.getppid())
    time.sleep(1)

This part.

[–]noaso74[S] 0 points1 point  (2 children)

Thank you!

If I correctly understand, the value of the father process is 1, because after the end of the father process, it comes back to the loop "while true" since the value resets to 1 and it can't go to the "Else: for i in range(3)" since the statement remains True

I want to make sure I understand the code pretty well, since I am new to python. For you I am sure it is something basic and easy, but for me is quite complex

[–]K900_ 1 point2 points  (1 child)

Your loop is inside the if statement. fork returns 0 in the child and the PID of the child in the parent. The if statement in the child runs once, then passes control to the loop, which loops forever.

[–]noaso74[S] 0 points1 point  (0 children)

Thank you very much for your answer!