How to find out number of files currently open by Java application?

后端 未结 5 1746
北恋
北恋 2020-12-13 09:01

Suppose a lot of what your application does deals with reading contents of files. It goes without saying that files that are opened then closed and life is good unless ... n

5条回答
  •  伪装坚强ぢ
    2020-12-13 09:20

    For the sake of completing/adding to the answer:

    Many people uses LSOF in Linux based system to monitor file descriptors and their details. However LSOF lists all kind of FDs(CWD,MEM) which is not returned by UnixOperatingSystemMXBean.getOpenFileDescriptorCount().

    Details can be found in http://www.ibm.com/developerworks/aix/library/au-lsof.html This may cause some confusion.

    To clarify UnixOperatingSystemMXBean.getOpenFileDescriptorCount() only shows application opened files descriptors. But LSOF (lsof -a -p ) lists other file descriptors opened by kernel on behalf of the process.

    To list only application level FDS one can filter out other type of FDs

    lsof -a -p yourprocid -d ^txt,^mem,^cwd,^rtd,^DEL

提交回复
热议问题