How to figure out the number of open files?

A

andreas kinell

Hi,

how can I figure out the number of open files under jdk-1.4.2?

Zsolt

open files in the system? opened by the program?
i don't really know, but in UNIX for example, every program has its own
file descriptor table. i don't think any user program can access those
tables from other programs (and therefore, java can't).

andreas
 
Z

Zsolt

Thank you James,

but I would like to know the number of files openned by my java application.
This application uses also 3rd party software where I have no control and
would like to see the total number of open files.

Zsolt
 
G

Gordon Beaton

but I would like to know the number of files openned by my java
application. This application uses also 3rd party software where I
have no control and would like to see the total number of open
files.

You can't do this using pure Java.

Some operating systems have mechanisms (e.g. a process file system)
that can be used to find out that information. For example, on linux
you could simply use File.listFiles() to get the contents of
/proc/self/fd.

lsof is a tool that can list the open files held by any process. If
it's available for your platform you could invoke it from
Runtime.exec(). See http://freshmeat.net/projects/lsof/ .

/gordon
 
J

John K

Zsolt, you could modify the mechanism you use to open the files. For
example, if you are using FileInputStream you could subclass it and
maintain a count of the number of created instances. This count would
represent the number of open files. When close() is called you can
decrement the count.

You mentioned you are using 3rd party software as well over which you
have no control. This makes the problem much more difficult. The only
possible solution to this that I can see is to do what I mention above
for every class that can open a file (no small task) and put that jar
onto the bootclasspath.
BTW, why do you need to know the number of open files?

-John K
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top