Daemonize?

Neil Schemenauer nas at python.ca
Sat Sep 7 19:49:57 CEST 2002


Oren Tirosh wrote:
>     devnull = os.open('/dev/null', 0)
>     os.dup2(devnull, 0)
>     os.dup2(devnull, 1)
>     os.dup2(devnull, 2)
> 
> This is safer because it prevents these file descriptors from being reused.

Better:

    os.close(sys.__stdin__.fileno())
    os.close(sys.__stdout__.fileno())
    os.close(sys.__stderr__.fileno())
    os.open('/dev/null', 0)
    os.dup(0)
    os.dup(0)

 pedanticly-y'rs Neil




More information about the Python-list mailing list