-
-
Save lukexie/e5c545c5e0f1e4661f376d30c67e32d0 to your computer and use it in GitHub Desktop.
example for double fork
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
# c.f. https://stackoverflow.com/a/5386753 | |
import os | |
import sys | |
print('pre-fork: pid=%d, pgid=%d, sid=%d' % (os.getpid(), os.getpgid(0), os.getsid(0))) | |
pid = os.fork() | |
if pid > 0: | |
sys.exit(0) | |
print('1st_fork: pid=%d, pgid=%d, sid=%d' % (os.getpid(), os.getpgid(0), os.getsid(0))) | |
os.setsid() | |
print('setsid : pid=%d, pgid=%d, sid=%d' % (os.getpid(), os.getpgid(0), os.getsid(0))) | |
pid = os.fork() | |
if pid > 0: | |
sys.exit(0) | |
print('2nd_fork: pid=%d, pgid=%d, sid=%d' % (os.getpid(), os.getpgid(0), os.getsid(0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment