Recently I ran into this issue in one of our production machines. The actual issue from PHP looked like this:

fopen(dberror_20110308.txt): failed to open stream: Too many open files

I am running LAMP stack along with memcache in this machine. I also run a couple of Java applications in this machine. While I did increase the limit on the number of files that can be opened to 10000 (from 1024), I would really like to know if there is an easy way to track this (# of files open at any moment) as a metric. I know lsof is a command which will list the file descriptors opened by processes. Wondering if there is any other better (in terms of report) way of tracking this using say, nagios.

  • you mentioned LAMP Apache can not handle 10K connection simultaneously.For connections worth 10K or more you need a different web server known as lighttpd. Mar 11, 2011 at 6:55

3 Answers 3


You can have a look at /proc/sys/fs/file-nr

cat /proc/sys/fs/file-nr
3391    969     52427
|        |       |
|        |       |
|        |       maximum open file descriptors
|        total free allocated file descriptors
total allocated file descriptors

Total allocated file descriptors means the number of file descriptors allocated since boot. This can be thought of as a high water mark of max files open at one time. As these free up they go into the 2nd colmn, so the number of open files at any given time will be column 1 - column 2.

  • In my machine the vales are 1020-0-1106685. Is this is normal? Doesn't the issue comes up at the user level, since it is possible to limit the number of files that can be opened (at any time) for any user?
    – Ram
    Mar 11, 2011 at 9:19
  • Modern Kinux Kernel's always have 0 as the 2nd one. What this says is that you currently have 1020 allocated (and used) file descriptors across the system and a limit of 54427 across the system. Presumably you could find all process id owned by the httd user and then wc -l /proc/<all_process_id's>/fd.
    – Decado
    Mar 11, 2011 at 10:55

/proc/sys/fs/file-nr shows the number of file descriptors open system-wide and the system-wide maximum. For individual processes, you can look at /proc/$pid/fd/*.


/proc/sys/fs/file-nr gives you the total number of open files on the system (and there is a limit on this) but your current problem is the number of open files per-process

Each open file is represented by a file in /proc/pid/fd

So you just need to identify the pids for the processes that are opening lots of files (looks like your database is the problem) and count the corresponding files.

But I do think its a little odd that it seems to be a DB which has too many open files. And is unable to open a txt file?

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.