On Tue, 14 Nov 2000, George Young wrote:

> my pygtk app forks and execs another process which it
> wants to completly disassociate from the parent. 
> It seems that one of the techniques necessary is for the child to
> dup2 and then close all it's files, e.g.:
>       fdnull = open('/dev/null')
>             stderr_d = os.dup2(fdnull.fileno(), sys.stderr.fileno())
>             stdin_d = os.dup2(fdnull.fileno(), sys.stdin.fileno())
>             stdout_d = os.dup2(fdnull.fileno(), sys.stdout.fileno())
>             fdnull.close()
> This works fine except for the connection to the X server.
> Guessing and handcoding the number, e.g.:
>       foo = os.dup2(fdnull.fileno(), 5)

You probably want to set the FD_CLOEXEC fcntl on all file descriptors >= 3
(as 0,1,2 are stdin,out and err).  There is a sysconf call to get the
maximum file descriptor number, but I don't know if this is available from
python.  So except for getting the maximum file descriptor number, the
rest can be done with the fcntl and FCNTL modules.

James.


_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to