linux – 文件描述符的数量:/ proc / sys / fs / file-nr和/ pr
我想检查实际使用了多少个文件描述符:
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 解决方法
lsof仅列出进程ID.要获取有关线程的信息,您应该使用ps -eLf.根据
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). 我会通过运行来计算打开文件描述符的数量: 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中分配的文件句柄数?我想它们是由分叉的子进程创建的:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |