From: Eric Schwartz Date: 2004-08-25T05:20:40+09:00 Subject: Re: Find the number of open files Charles Mills writes: > I am unittesting a C extension. The extension opens files using > open(). I want to make sure that the extension closes all the files it > opens (when errors occur or whatever). Call me crazy, but what's wrong with adding each file descriptor you open into a list, and then traversing that list at error time (or whatever) to make sure they're all closed? > So I figured getting a count of open file descriptors before the > extension code is called and after it is finished would enable me to do > this. I'm not sure what that would buy you. If your extension code can take a block, you're completely screwed-- that block may open new filehandles, or close old ones, and your count-based approach would be totally out into the weeds. Even if it doesn't, signal handlers and other asynchronous code may open or close them without your explicit knowledge. Besides, knowing how many descriptors are open is a far cry from knowing *which* descriptors are open, which is necessary to close() them. -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton.