Skip to content

Instantly share code, notes, and snippets.

@ducin
Created November 3, 2013 12:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducin/7289863 to your computer and use it in GitHub Desktop.
Save ducin/7289863 to your computer and use it in GitHub Desktop.
scanning parent/child process IDs using os.fork
import os
parent_pid = os.getpid()
print "[parent] starts PID: %d" % (parent_pid, )
forked_pid = os.fork()
if forked_pid == 0:
print "[child] child process can't use os.fork() PID, since it's %d" % (forked_pid, )
print "[child] but it can reevaluate os.getpid() to get it's own PID: %d" % (os.getpid(), )
else:
print "[parent] parent process have created child with PID: %d" % (forked_pid, )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment