lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


--- Mark Edgar <medgar123@gmail.com> wrote:

> On 3/5/07, gary ng <garyng2000@yahoo.com> wrote:
> > However, given the generic and widespread usage of
> > fork()/exec(), even 2 file descriptors may not be
> > enough. As they are in general passed to childs
> which
> > unless explicitly closed in the forked child,
> would
> > have the same effect as it is now. So a shutdown()
> is
> > still needed which effectively means, close this
> > pipe/socket regardless of how many fd are dup().
> 
> Neglecting to explicitly (or implicity via
> FD_CLOEXEC) close unused
> descriptors is a bug in the program, not a flaw in
> the design of
> POSIX.
> 
If it is just exec(), this may be true. But what if I
just need to fork() and run seperately for something
else(like spawn and wait or just running other things
in seperate process space) ? I would still need to
pick and close things to prevent this situation. It is
easy to just identify the two handles involved(like
the popen2 example) but when there are more forking
than a simple one to one(like parent multiple child), 
it can become complicated. As the parent pipe with one
child may leak to other child during forking().

I ended up doing a loop like this immediately after
fork():

for i=2,256 do close(i) end

i.e. only limit the communication using 0/1 bewteen
parent/child.

Sure it is a bug(as anything not function as expected
is) but it is still complication. .



 
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091