lsof apenas lista o ID do Processo . Para obter informações sobre tópicos, você deve usar ps -eLf . De acordo com o man proc :
/proc/[pid]/task (since Linux 2.6.0-test6)
This is a directory that contains one subdirectory for each
thread in the process. The name of each subdirectory is the
numerical thread ID ([tid]) of the thread (see gettid(2)).
Within each of these subdirectories, there is a set of files
with the same names and contents as under the /proc/[pid]
directories. For attributes that are shared by all threads,
the contents for each of the files under the task/[tid]
subdirectories will be the same as in the corresponding file
in the parent /proc/[pid] directory (e.g., in a multithreaded
process, all of the task/[tid]/cwd files will have the same
value as the /proc/[pid]/cwd file in the parent directory,
since all of the threads in a process share a working
directory). For attributes that are distinct for each thread,
the corresponding files under task/[tid] may have different
values (e.g., various fields in each of the task/[tid]/status
files may be different for each thread).
In a multithreaded process, the contents of the
/proc/[pid]/task directory are not available if the main
thread has already terminated (typically by calling
pthread_exit(3)).
Eu calcularia o número de descritores de arquivos abertos executando:
ps -eL | awk 'NR > 1 { print $1, $2 }' | \
while read x; do \
find /proc/${x% *}/task/${x#* }/fd/ -type l; \
done | wc -l
O resultado é 17270.
Vamos ver quantos descritores de arquivos foram alocados desde a inicialização:
cat /proc/sys/fs/file-nr
11616 0 398855
Por que há um excesso de números de descritores de arquivos em /proc/[pid]/task/[tid]/fd sobre o número de identificadores de arquivos alocados em /proc/sys/fs/file-nr ? Suponho que eles sejam criados por processos filhos fork ed:
man fork :
The child inherits copies of the parent's set of open file descriptors.
POSIX.1 also requires that threads share a range of other attributes (i.e., these attributes are process-wide rather than per-thread): - process ID
parent process ID
process group ID and session ID
controlling terminal
user and group IDs
open file descriptors