linux进程fd数量,linux – 文件描述符的数量:/ proc / sys / fs / file-nr和/ proc / $pid / fd之间有什么不同?...

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).@H_301_37@

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@H_301_37@ descriptors.

POSIX.1 also requires that threads share a range of other@H_301_37@ attributes (i.e.,these attributes are process-wide rather than@H_301_37@ per-thread):@H_301_37@ – process ID

parent process ID

process group ID and session ID

controlling terminal

user and group IDs

open file descriptors

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值