As I spawn several processes in a loop, I hit the maximum number of open files handles and the for loop breaks.

When I count the open file handles using lsof I get:

$ lsof | wc -l

However checking fs.file-nr returns:

$ sysctl fs.file-nr
fs.file-nr = 35328      0       6553201

I expected the first number to be 1464377.

I have a couple of questions:

  1. What's the difference between the output of lsof (1464377) and file-nr (35328).

  2. The maximum seems to be 6553201, which looks rather arbitrary. What's the maximum value for this number?


as per man lsof

An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.) A specific file or all the files in a file system may be selected by path.

So number of line in lsof is likely much more than actual file descriptor.

See this reated question : https://serverfault.com/questions/485262/number-of-file-descriptors-different-between-proc-sys-fs-file-nr-and-proc-pi

| improve this answer | |

@Archemar is right. I'm late with answer. I check it (exclude character special file, network file, dirs ...):

$ lsof /|grep -v DIR|wc -l 

$ sysctl fs.file-nr
fs.file-nr = 1280   0   98018

There are 1191 opened files and 1280 allocated handles. Values are very nearly.

Kernel documentation about fs partition on sysctl

| improve this answer | |
  • True, I get closer values but they are still off by a factor of 3. grepped lsof giving me 11410 and file-nr giving me 32640. – Paulo Matos Mar 19 '18 at 7:28

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.