lua-users home
lua-l archive

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


On Mon, Mar 07, 2011 at 05:32:28PM +0100, Axel Kittenberger wrote:
> >  Both do the job, but os.exit() will cause the process to end immediately
> > without the garbage collector doing a final clean up.  I found this out the
> > hard way when I had some code that would flush a file and close it when the
> > object was garbage collected, but calling os.exit() would leave the file in
> > an inconsistent state.  Doing a 'return' from the script would cause the GC
> > to kick in.
> 
> I suppose you had some extra on "__gc"? I always believed the Linux
> kernel will call a clean close() on all open file descriptors when
> terminating a process.

Assuming these are file descriptors created with io.open or io.popen then they
have C-library FILE* objects backing them.  These can hold writes in memory
until they need to be flushed, are flushed explicitly, or are closed with
fclose().  No amount of kernel-based cleanup will help with that :-)

D.

-- 
Daniel Silverstone                         http://www.digital-scurf.org/
PGP mail accepted and encouraged.            Key Id: 3CCE BABE 206C 3B69