From: Robert Klemme Date: 2004-08-26T22:50:37+09:00 Subject: Re: Find the number of open files "Charles Mills" schrieb im Newsbeitrag news:A42068F2-F60A-11D8-93A8-000A95A27A10@freeshell.org... > > On Aug 24, 2004, at 1:05 PM, Robert Klemme wrote: > > > > > "Charles Mills" schrieb im Newsbeitrag > > news:267B9838-F607-11D8-93A8-000A95A27A10@freeshell.org... > >> On Aug 24, 2004, at 12:41 PM, Charles Mills wrote: > >> > >>> Is there an easy way to find out the number of open files held by a > >>> process (using C or Ruby)? > >>> > >> I think the way I phrased the question above makes the problem sound > >> harder than it is... > >> 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). > >> > >> 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. > > > > IMHO this would not be safe unless you disable threading: another > > thread > > could open or close files in the meantime. > > > Good point. > The unittests are pretty simple. Basically more or less testing a C > library (not multithreaded) wrapped in Ruby. > There is a point where all Ruby data gets converted to C > types/structures and passed to the C library functions I am testing. > However, the library functions handle opening and closing files > themselves. Yeah, but then how about my suggestion: > > Why don't you just create a customized class that does the bookkeeping? > > Alternatively you could hand in open IO objects, if the logic of your > > extension allows this. You can get the file descriptor by using IO#fileno. If you'd uncover a bit more of your extension's functionality, we might come up with better solutions... Kind regards robert