"fork and exit" needed?
Nick Craig-Wood
nick at craig-wood.com
Tue Nov 28 05:30:09 EST 2006
Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
> In <8osmm21skionildtnme1j0nvqbla6oqk72 at 4ax.com>, Vincent Delporte wrote:
>
> > Anyone knows if those lines are necessary, why, and what their
> > alternative is in Python?
> >
> > open STDOUT, '>/dev/null';
>
> sys.stdout = open(os.devnull, 'w')
This doesn't have the desired effect
If you run this
import os,sys,time
print os.getpid()
sys.stdout = open(os.devnull, 'w')
time.sleep(60)
It prints its pid.
$ ls -l /proc/32004/fd
total 4
lrwx------ 1 ncw ncw 64 Nov 28 09:55 0 -> /dev/pts/17
lrwx------ 1 ncw ncw 64 Nov 28 09:55 1 -> /dev/pts/17
lrwx------ 1 ncw ncw 64 Nov 28 09:55 2 -> /dev/pts/17
l-wx------ 1 ncw ncw 64 Nov 28 09:55 3 -> /dev/null
That quite clearly shows that stdout isn't /dev/null which is required
for proper deamonisation under unix.
I'm not sure how you do open stdout to /dev/null in python though!
I suspect something like this...
import posix
posix.close(1)
posix.open("/dev/null", posix.O_WRONLY)
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list