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
Best Answer
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
: