Daemonizing a python programme.

William Annis annis at biostat.wisc.edu
Mon Mar 26 09:24:28 EST 2001


Coy Krill <ckrill at qvlinc.com> writes:
> class NullDevice:
>     def write(self, s):
>         pass
> 
> def daemonize():
>     if (not os.fork()):
>         # get our own session and fixup std[in,out,err]
>         os.setsid()

        I include these here:

        os.chdir(some_sensible_root_dir_for_core_files)
        os.umask(000)     # or whatever seems sensible

        See chapter 13, "Daemon Processes," pp.415-425 of "Advanced
Programming in the Unix Environment" by W. Richard Stevens for a full
treatment.

>         sys.stdin.close()
>         sys.stdout = NullDevice()
>         sys.stderr = NullDevice()

        This is curious.  Why not just close down STDOUT and STDERR,
too? 

-- 
William Annis - System Administrator - Biomedical Computing Group
annis at biostat.wisc.edu                       PGP ID:1024/FBF64031
Mi parolas Esperanton - La Internacian Lingvon  www.esperanto.org



More information about the Python-list mailing list