Python and Daemons
thm at duke.edu
Wed Feb 27 17:49:59 CET 2002
Justin Sheehy <justin at iago.org> wrote in message news:<mailman.1014416559.28231.python-list at python.org>...
> Dieter Lunn <theguru at mb.sympatico.ca> writes:
> > I was wondering how to write a linux daemon using Python.
> This is what I use:
> class Log_out:
> '''file-like dummy device, used for daemonization
> writes are redirected into our logging object'''
> def write(self, s):
> def daemonize():
> "cause this process to becaome a daemon"
> if os.fork() != 0:
> if os.fork() != 0: # 2nd fork is widely recommended
> os._exit(0) # though not always needed
> os.chdir("/") # not strictly necessary, but a good idea
> sys.stdout = Log_out()
> sys.stderr = Log_out()
> debugmsg is a local function which calls a function in my logging library.
Can someone say why the 2nd fork is widely recommneded?
More information about the Python-list