Skip to content

Instantly share code, notes, and snippets.

@RedHatter
Last active January 2, 2016 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedHatter/8264094 to your computer and use it in GitHub Desktop.
Save RedHatter/8264094 to your computer and use it in GitHub Desktop.
Attempt to completely fork from parent process.
#!/usr/bin/python
import time, os, sys
# do the UNIX double-fork magic
pid = os.fork()
if pid > 0:
# parent process, exit
sleep(5)
sys.exit(0)
# os.setsid()
# do second fork
pid = os.fork()
if pid > 0:
# exit from second parent
sleep(10)
os._exit(os.EX_OK)
# do stuff
time.sleep(15)
# all done
os._exit(os.EX_OK)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment