Created
September 21, 2010 17:54
-
-
Save Motoma/590131 to your computer and use it in GitHub Desktop.
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
#! /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