C
Charles Mills
Is there an easy way to find out the number of open files held by a
process (using C or Ruby)?
-Charlie
process (using C or Ruby)?
-Charlie
I think the way I phrased the question above makes the problem soundIs there an easy way to find out the number of open files held by a
process (using C or Ruby)?
Is there an easy way to find out the number of open files held by a
process (using C or Ruby)?
Is there an easy way to find out the number of open files held by a
process (using C or Ruby)?
-Charlie
Charles Mills said: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.
*nix only, but
man lsof
man fuser
-a
Charles Mills said: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.
Good point.IMHO this would not be safe unless you disable threading: another
thread
could open or close files in the meantime.
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.
That is a good idea.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?
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
Charles Mills said: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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.