3

I have Centos 6.7 running java application via a wrapper programme. So first I ran this.

lsof -p 15200 | wc -l and I got the results immediately as 200

next I ran this lsof -p 15232 | wc -l I keep taking too long and never generated any results. What other method can I use to get the total open files? I need to know cause my system keep hanging after certain time. I will maybe need to increase the open file size.

  • 1
    You seem to be focusing on the number of open files, assuming that this is the cause of your system freezing. That appears unlikely to me, and also makes this question a case of an XY problem. We can probably answer this, but I think you are more likely to get useful answers if you focus on why your system is freezing. Note that now that this question has been answered, you shouldn't change it too much, as such a change would; instead, you may want to ask a new question and include relevant details about diagnosing the freezing. – a CVn May 19 '17 at 20:43
  • I am not assuming but I am trying to narrow down my problem to check is this a related issue thus I would like to find out if the number of files are keep growing and no shrinking. Actually I am getting too many close_wait in my socket application I notice this when the the system start to freeze – user8012596 May 19 '17 at 20:48
  • That process may indeed be related to your freeze. Do you know what it is? – Julie Pelletier May 19 '17 at 20:57
  • Sometimes, I find that IP address to host name resolution is what causes lsof to slow down. Try adding a -n option. (you may also want to add -P and -M). – Stéphane Chazelas May 19 '17 at 21:01
  • 1
    @JuliePelletier yes is my socket application and suddenly I see that close wait count keep increasing it takes a while almost after a week then it behaves this way then I restart my application is back to normal. – user8012596 May 19 '17 at 21:09
6

You can get the number files opened by a process identified by a PID, for instance 15232, doing:

ls -l /proc/15232/fd | wc -l

from the Debian lists:

I am trying to figure out the meaning of:

/proc/$PID/fd/*

files.

These are links that point to the open files of the process whose pid is $PID. Fd stands for "file descriptors", which is an integer that identifies any program input or output in UNIX-like systems.

This is also actually where the lsof command drinks the information to give you the files of a process.

This is a feature of the linux kernel, and is distribution agnostic.

  • Mine is centos 6.7 so will this work? – user8012596 May 19 '17 at 20:46
  • Yes, this is a linux kernel feature. – Rui F Ribeiro May 19 '17 at 20:46
  • yes its working can I understand why my original command lsof -p 15232 | wc -l is not working for this particular pid but works for other pid. Another thing how to find out what is actual maximum open files can be open and what is the limit I am hitting now ? – user8012596 May 19 '17 at 20:54
  • @user8012596: don't post new questions in comments. Search online and if you can't find it, ask a new question. Do note however that reaching the limit should not freeze a computer but instead cause some programs to crash. – Julie Pelletier May 19 '17 at 20:55
  • @rui is actually not freezing my centos but just causing my db and app to almost freezing. – user8012596 May 19 '17 at 20:58

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.