Skip to content

Instantly share code, notes, and snippets.

@Motoma
Created September 21, 2010 17:54
Show Gist options
  • Save Motoma/590131 to your computer and use it in GitHub Desktop.
Save Motoma/590131 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
from os import fork, chdir, setsid, umask
from sys import exit
def main():
while 1:
#main daemon process loop
# Dual fork hack to make process run as a daemon
if __name__ == "__main__":
try:
pid = fork()
if pid > 0:
exit(0)
except OSError, e:
exit(1)
chdir("/")
setsid()
umask(0)
try:
pid = fork()
if pid > 0:
exit(0)
except OSError, e:
exit(1)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment