I would like to check how many file descriptors are actually used:
cat /proc/sys/fs/file-nr
12750 0 753795
The first column (12750) indicates the number of file descriptors allocated since boot.
I would like to know why the number from the following command is different (assuming this one liner is returning the correct value:
for pid in $(lsof | awk '{ print $2 }' | uniq); do find /proc/$pid/fd/ -type l 2>&1 | grep -v "No"; done | wc -l
11069
lsof
only lists the Process ID. To get info about threads, you should useps -eLf
. According to theman proc
:I would calculate the number of open file descriptors by running:
The result is 17270.
Let's see how many file descriptors allocated since boot:
Why there is an excess of number of file descriptors in
/proc/[pid]/task/[tid]/fd
over the number of allocated file handles in/proc/sys/fs/file-nr
? I suppose that they are created byfork
ed child processes:man fork
:man pthreads
:http://www.netadmintools.com/part295.html 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.