How to close all files between fork and exec?

Harald Kirsch kirschh at lionbioscience.com
Fri Jan 19 03:41:41 EST 2001


aahz at panix.com (Aahz Maruch) writes:

> In article <yv27l3t483r.fsf at lionsp093.lion-ag.de>,
> Harald Kirsch  <kirschh at lionbioscience.com> wrote:
> >aahz at panix.com (Aahz Maruch) writes:
> >> In article <yv27l3upooj.fsf at lionsp093.lion-ag.de>,
> >> Harald Kirsch  <kirschh at lionbioscience.com> wrote:
> >>>
> >>>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). 
> >> 
> >> Why not simply keep track of all open files in a dict or list?
> >
> >Thereby duplicating the work the operating system does anyway? And how
> >would a module for forking special processes keep track of the files
> >opened by the main program calling it? Hmm...
> 
> from fork import open
> 
Hmm, this is becoming somehow interesting because I have got no idea
why you think this relates in any way to my question. Either you try
to tease me or we have a communication problem. But I think I should
stay calm and try to start all over:

Suppose you have the assignment to write a module for me which, for
whatever reasons, has to fork/exec certain subprocesses. I want to use
your module as a service in my software. But my software will have a
whole bunch of files open when it calls your module. How did your
module keep track of all these files so that it is able to close them
all before execing. --- If you now say that your module cannot do that
and that it would be the obligation of my software to close unneded
files before calling your module, I at least start to understand your
arguments. However I maintain the opinion that this would be nonsense.


> As for your first question, you're always responsible of keeping track
> of whatever resources you're using; it's just that sometimes, the
> language you're using provides conveniences to make that easier.

Philosophically deep, general statements don't really help me on
practical problems. 

Thanks anyway,
  Harald Kirsch

-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION Bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list