source: mergebot/trunk/mergebot/daemonize.py

Last change on this file was 17, checked in by retracile, 15 years ago

Mergebot: redesigned implementation. Still has rough edges.

File size: 513 bytes
Line 
1"""Implementation of the daemonizing process
2from "Advanced Programming in the UNIX Environment" by W. Richard Stevens,
31993.
4"""
5import os
6import sys
7
8def daemonize():
9    # Let's assume nothing ever goes wrong...
10    pid = os.fork()
11    if pid:
12        sys.exit(0)
13    os.setsid()
14    os.chdir('/')
15    os.umask(000)
16    for n in range(1024):
17        try:
18            os.close(n)
19        except OSError:
20            pass
21    os.open('/dev/null', os.O_RDONLY)
22    os.open('/dev/null', os.O_WRONLY)
23    os.dup(1)
Note: See TracBrowser for help on using the repository browser.