List all currently open file handles?

Thorsley picture Thorsley · Jul 30, 2010 · Viewed 15.3k times · Source

Possible Duplicate:
check what files are open in Python

Hello,

Is it possible to obtain a list of all currently open file handles, I presume that they are stored somewhere in the environment.

I am interested in theis function as I would like to safely handle any files that are open when a fatal error is raised, i.e. close file handles and replace potentially corrupted files with the original files.

I have the handling working but without knowing what file handles are open, I am unable to implement this idea.

As an aside, when a file handle is initialised, can this be inherited by another imported method?

Thank you

Answer

dimba picture dimba · Jul 30, 2010

lsof, /proc/pid/fd/