Getting Python to fork?

Jon Ribbens jon+usenet at unequivocal.co.uk
Mon Feb 4 10:03:44 EST 2008


On 2008-02-04, Bernard <bernard.chhun at gmail.com> wrote:
>             #Fork and commit suicide
>             if os.fork():
>                 sys.exit(0)

I'm pretty sure that should be os._exit(0)

>             #What to do in parent process

This is now the child process.

>                 sys.stdin = open('/dev/null')
>                 sys.stdout = open('/dev/null', 'w')
>                 sys.stderr = open('/dev/null', 'w')

I think that's changing Python's idea of stdin etc but not the
operating system's idea of them. You won't be closing the original
file descriptors, and if you run any subprocesses they will end up
with the original stdin/out/err. Unless sys.stdin is more magic
than I'm aware of.



More information about the Python-list mailing list