Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created August 7, 2015 16:00
Show Gist options
  • Save Kwpolska/1f80b64df2cd181df855 to your computer and use it in GitHub Desktop.
Save Kwpolska/1f80b64df2cd181df855 to your computer and use it in GitHub Desktop.
os.fork demo
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