1

I need to check the number of file descriptors which are open by a Java process. The output of lsof is almost 40000 lines long. Here's just the beginning:

COMMAND   PID     USER   FD      TYPE             DEVICE  SIZE/OFF     NODE NAME
java    12003 jboss  cwd       DIR              253,7      4096  1835012 /obcdn/Jboss/bin
java    12003 jboss  rtd       DIR              253,0      4096        2 /
java    12003 jboss  txt       REG              253,7      7336  2621459 /obcdn/java1.8/bin/java
java    12003 jboss  mem       REG              253,2    111080   171382 /usr/lib64/libresolv-2.17.so
java    12003 jboss  mem       REG              253,2     27776   133531 /usr/lib64/libnss_dns-2.17.so
java    12003 jboss  mem       REG              253,7    278078  1966631 /obcdn/Jboss/modules/system/layers/base/org/yaml/snakeyaml/main/snakeyaml-1.15.0.redhat-1.jar
java    12003 jboss  mem       REG              253,7    360979  1835896 /obcdn/Jboss/modules/system/layers/base/org/apache/james/mime4j/main/apache-mime4j-0.6.0.redhat-5.jar
java    12003 jboss  mem       REG              253,7     32957  1835471 /obcdn/Jboss/modules/system/layers/base/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/main/jackson-module-jaxb-annotations-2.5.4.redhat-1.jar
java    12003 jboss  mem       REG              253,7     28742  1835469 /obcdn/Jboss/modules/system/layers/base/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/main/jackson-jaxrs-base-2.5.4.redhat-1.jar
java    12003 jboss  mem       REG              253,7     16843  1835470 /obcdn/Jboss/modules/system/layers/base/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider

So it appears that the process is being using almost 40000 file descriptors, that seems a bit too much, also what I'm worried about is that an ulimit -a shows this maximum number of open files

open files                      (-n) 40000

Just to confirm my analysis: is each line of the lsof output actually a FD opened, or should I grep the output somehow to have the correct count ? Thanks

  • 3
    You can also do ls /proc/$PID/fd/|wc -l where PID is the process id. – meuh Jul 15 '17 at 9:42
2

mem aren't FDs, they're from mmap(). So I would grep -v " mem " to be sure. cwd, rtd, and txt are not FDs either, but there should be exactly one of each, so they won't have a very significant effect on your numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.