Created
August 7, 2015 16:00
-
-
Save Kwpolska/1f80b64df2cd181df855 to your computer and use it in GitHub Desktop.
os.fork demo
This file contains hidden or 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 time | |
print("forking...") | |
pid = os.fork() | |
print("done!") | |
if pid == 0: | |
print("hello, I am the child") | |
else: | |
print("hello, I am the parent") | |
print("and we work simultaneously") | |
print("and when the parent dies, a prompt appears") | |
if pid == 0: | |
print("child: still alive") | |
time.sleep(1) | |
print("child: alive and kickin'") | |
time.sleep(5) | |
print("child: goodbye") | |
else: | |
print("parent: goodbye") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment