From: Charles Mills Date: 2004-08-25T05:17:45+09:00 Subject: Re: Find the number of open files 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. -Charlie > 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. > > Kind regards > > robert > >