Could someone explain limit on open files in linux? The problem is that one of my applications if reporting "Too many open files".

I have

ulimit -n


cat /proc/sys/fs/file-max


cat /proc/sys/fs/file-nr

So I already have 1536 > 1024. What is ulimit -n then? This is very confusing.

1 Answer 1


ulimit shows the per-process maximum. The two files under /proc shows system-wide numbers.

From ServerFault:

file-max is the maximum File Descriptors (FD) enforced on a kernel level, which cannot be surpassed by all processes without increasing. The ulimit is enforced on a process level, which can be less than the file-max.

From http://www.linuxvox.com/post/what-are-file-max-and-file-nr-linux-kernel-parameters/:

What is the file-max parameter and what should we tune it to? The linux documentation definition is that file-max denotes the maximum number of filehandles that the Linux kernel will allocate.


How do I know if I’m getting close to hitting this limit on my server? Run the command: cat /proc/sys/fs/file-nr. This will return three values, denote the number of allocated file handles, the number of allocated but unused file handles, and the maximum number of file handles. Note that file-nr IS NOT a tunable parameter. It is informational only. On my server, this returns: 3488 0 793759. This means that currently, my server has only allocated 3488 of the 793,759 allocation limit and is in no danger of hitting this limit at this time.

  • thanks! which command I can use to estimate by-process fd count to compare with ulimit -n?
    – xaxa
    Jun 3, 2018 at 12:11
  • @xaxa I imagine that lsof would be useful for counting the number of open files for a particular process.
    – Kusalananda
    Jun 3, 2018 at 12:51

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.