How Many Open Files?
Fri, 2009.01.30 - 18:54 — müzso
We knew the answer to this question once, back when the world was young and full of truth. Without hesitation, we'd have spouted "Just take the output of lsof | wc -l!" And it's true enough, in a general sort of way. But if you asked me the same question now, my answer would be: "Why do you want to know?"
Are you, for instance, attempting to determine whether the number of open files is exceeding the limit set in the kernel? Then the output of lsof will be practically useless.
(...)
Comments
Obfuscated
On the other hand the proc filesystem exposes these, too. For example program object are listed under /proc/<pid>/object.
Re: Obfuscated
lsof
.He even wrote in the last paragraph: "Quite a difference. This process has only four open file descriptors, but there are thirty open files associated with it. Some of the open files which are not using file descriptors: library files, the program itself (executable text), and so on as listed above. These files are accounted for elsewhere in the kernel data structures (cat /proc/PID/maps to see the libraries, for instance), but they are not using file descriptors and therefore do not exhaust the kernel's file descriptor maximum."
And more over: "What is an open file?
Is an open file a file that is being used, or is it an open file descriptor? A file descriptor is a data structure used by a program to get a handle on a file, the most well know being 0,1,2 for standard in, standard out, and standard error. The file-max kernel parameter refers to open file descriptors, and file-nr gives us the current number of open file descriptors. But lsof lists all open files, including files which are not using file descriptors - such as current working directories, memory mapped library files, and executable text files."
I think that both of you know exactly what you're talking about and both of you share and agree on the same knowledge. The difference is simply terminology. He considers a file "open" even if it was opened by the kernel (btw. ... I assume even shared libraries, program text image, etc. are opened by the kernel using
open(2)
lsof
lists all those additional files for a process, because they are indeed "associated" since the process needs them in order to work properly.I think the point of the article was to enlighten and not to "obfuscate".
Okay, then just let's stick
Re: Okay, then just let's stick
I'm sure their terminology is the least understood in the world.
But hey: it's a free world. Everybody can have their own understanding of the "open files" term. Just don't judge people too early based on their definition.