cat /proc/sys/fs/file-nr 12750 0 753795
第一列(12750)表示自引导以来分配的文件描述符的数量.
我想知道为什么以下命令中的数字是不同的(假设这一个班轮正在返回正确的值:
for pid in $(lsof | awk'{print $2}’| uniq);找到/ proc / $pid / fd / -type l 2>& 1 | grep -v“不”;完成| wc -l
11069
解决方法
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 07001). 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 07002).
我会通过运行来计算打开文件描述符的数量:
ps -eL | awk 'NR > 1 { print $1,$2 }' | \ while read x; do \ find /proc/${x% *}/task/${x#* }/fd/ -type l; \ done | wc -l
结果是17270.
让我们看看自启动以来分配了多少文件描述符:
cat /proc/sys/fs/file-nr 11616 0 398855
为什么/ proc / [pid] / task / [tid] / fd中的文件描述符数量超过/ proc / sys / fs / file-nr中分配的文件句柄数?我想它们是由分叉的子进程创建的:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。