Mercurial > templog
changeset 371:7dec59b7eeef
cheap_daemon()
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 26 Jun 2012 21:36:54 +0800 |
parents | aaa94f90eaa1 |
children | dae8eb26eaa3 |
files | server/ts.py server/utils.py |
diffstat | 2 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/server/ts.py Tue Jun 26 21:21:51 2012 +0800 +++ b/server/ts.py Tue Jun 26 21:36:54 2012 +0800 @@ -172,6 +172,9 @@ def main(): next_wake_time = 0 + if '--daemon' in sys.argv: + utils.cheap_daemon() + while True: sock = None try:
--- a/server/utils.py Tue Jun 26 21:21:51 2012 +0800 +++ b/server/utils.py Tue Jun 26 21:36:54 2012 +0800 @@ -97,3 +97,24 @@ uc += 1 i += 1 return crc + +def cheap_daemon(): + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print>>sys.stderr, "Bad fork()" + sys.exit(1) + + os.setsid() + + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print>>sys.stderr, "Bad fork()" + sys.exit(1) + +