N
N
Niko True2014-02-27 16:01:44
linux
Niko True, 2014-02-27 16:01:44

How to see the number of open files in the system?

Hello, I
ran into an incomprehensible situation:
lsof | wc -l gives 372,
cat /proc/sys/fs/nr_open gives 1048576,
cat /proc/sys/fs/file-nr gives 832 0 50170. The
question is, which data shows correctly how many files are open on the system. The matter is that there is a server on freebsd and there if I am not mistaken it can be looked through sysctl kern.openfiles.
PS you need this to configure the sending of messages when the number of files allows a certain limit.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
custos, 2014-02-27
@buloshnik

Open files are shown of course by lsof, and the kernel options are more about descriptors, these specific ones mean:
nr_open - hard limit on open descriptors, file-max parameter - soft limit is more useful.
file-nr - Shows allocated descriptors, unused and maximum, respectively. The number of allocated descriptors is greater, because the kernel allocates them dynamically and does not deallocate them, so their number keeps growing.

A
Alexey Maksimov, 2018-06-09
@A_Maksimov

The command "lsof | wc -l" shows a much larger value than the total number of open files in the system at the moment actually.
This is due to the fact that the same files used by different processes get into the count several times.
To count the total number of open files, it is better to use the first value in the output of the "cat /proc/sys/fs/file-nr" command.
Or, if you still use lsof, then the output will have to be subjected to additional processing, removing duplicates.
How to check all open files by user or...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question