How to close all files between fork and exec?

Donn Cave donn at u.washington.edu
Wed Jan 17 13:24:20 EST 2001


Quoth Harald Kirsch <kirschh at lionbioscience.com>:
|
| Python has fork/exec. I want to use it. After fork and before exec I
| would like the child process to close all files other than 0, 1 and 2
| (i.e. standard input/output/error). 
|
| On some systems there is a constant like OPEN_MAX but I read that on
| recent Solaris versions there is no real limit to it.
| How do I get hold of the highest numbered open file descriptor, in
| particular in python?

Unfortunately it looks to me like no one has ever put getdtablesize()
in Python.  It isn't literally POSIX 1003.1, but I believe like other
things in the "posix" module is X/Open and widely supported on UNIX
type platforms.  That seems to me to be the way it's usually done in C,
as you probably know.

In Python, if there's anything like standard operating procedure, it's
simply to use a fixed value of 256.  If that's low, it's also economical -
an invalid descriptor is a little more expensive to close in Python
because of the requirement for exception handling.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list