From: Charles Mills Date: 2004-08-25T06:17:30+09:00 Subject: Re: Find the number of open files On Aug 24, 2004, at 1:45 PM, Ara.T.Howard@noaa.gov wrote: > On Wed, 25 Aug 2004, Charles Mills wrote: > >> 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. > > define an xopen that updates a static var - then you won't have to > worry about > some other process/thread/function opening up files and killing your > test... > > cheerx. > > -a Yeah, if your curious that is what I am doing. The library that I am testing already uses functions that wrap open() and close(). So I am adding a global structure to that module to keeps track of the fd's in use. Should be a much more robust test - keeping track of which fd's are created using xopen and which are closed using xclose .... should be 1 to 1. Thanks for all the help, Charlie