Created
November 3, 2013 12:38
-
-
Save ducin/7289863 to your computer and use it in GitHub Desktop.
scanning parent/child process IDs using os.fork
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 | |
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