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

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

  1. Linux中的进程、线程和文件描述符

    说到进程,恐怕面试中最常见的问题就是线程和进程的关系了,那么先说一下答案: 在 Linux 系统中,进程和线程几乎没有区别 . Linux 中的进程就是一个数据结构,看明白就可以理解文件描述符.重定向 ...

  2. linux dup用法,Linux:dup和dup2文件描述符及函数解析,dupdup2

    Linux:dup和dup2文件描述符及函数解析,dupdup2 一.文件描述符 1.1 文件描述符概念 我们知道在Linux下一切皆文件,因此我们需要一个东西对这些文件进行管理,此时就需要文件描述符 ...

  3. Linux系统学习笔记:文件描述符标志

    文件描述符标志的概念 文件描述符标志(目前就只有一个close-on-exec): 它仅仅是一个标志,当进程fork一个子进程的时候,在子进程中调用了exec函数时就用到了这个标志.意义是执行exec ...

  4. linux unix域socket_从文件描述符到Socket

    回顾 在上一篇[谈谈我对学习Netty的看法]大致描述了学习netty整个知识的储备,今天就从最基础的文件描述符开始. 文件描述符 我们知道在linux系统中一切皆文件,而文件又可分为:普通文件.目录 ...

  5. Linux笔记(70)——文件描述符之ulimit命令

    当进程打开现有文件或创建新文件时,会受到文件描述符的限制. Linux系统中经常出现错误too many open files ,说明你打开的文件数量超过文件描述符的限制. 查看文件描述符大小: [r ...

  6. Linux 基础I/O :文件描述符,重定向,文件系统,软链接和硬链接,动态库和静态库

    文件描述符 重定向 文件系统 软链接和硬链接 动态库和静态库 文件描述符 上面两个接口分别是c语言的fread接口和linux的read接口,当我们在使用的时,可能会有疑问,为什么linux的io接口 ...

  7. Python 中如何解决 asyncio 文件描述符最大数量限制问题

    文章目录 问题复现 问题分析 事件循环 EventLoop I/O 多路复用 select 的缺点 解决方法 1.更换事件循环选择器 2.限制并发量 3.修改最大文件描述符限制 Windows Lin ...

  8. 文件读取 linux_Linux 进程、线程、文件描述符的底层原理

    说到进程,恐怕面试中最常见的问题就是线程和进程的关系了,那么先说一下答案:在 Linux 系统中,进程和线程几乎没有区别. Linux 中的进程其实就是一个数据结构,顺带可以理解文件描述符.重定向.管 ...

  9. linux进程文件描述符 vnode,Linux C编程详解:进程原理分析、文件描述符和文件记录表、文件句柄和文件原理...

    一.引言 文件操作是Linux C编程中其中的一项核心技术,实际上也相当重要,这里并不是说狭义上的那种文件操作,它也非常有助于理解和学习Linux系统.为什么这样说呢?因为在Unix/Linux的世界 ...

最新文章

  1. linux中断共享程序实现,如何在非实时linux上实现实时应用程序与内核模块之间共享存储器...
  2. 3亿人养老靠机器人?这家公司要在2030年实现,有谱
  3. 纯js制作的弹球游戏
  4. Python之路【第十二篇】:函数
  5. 源代码遭泄露,大疆员工被罚20万,判刑半年。
  6. OpenCV图像剪切的扩展和高级用法:任意裁剪,边界扩充
  7. dns的服务器地址是多少当前位置,dns的服务器地址设置为多少
  8. win 二进制门安装mysql_windows安装mysql2 gem(包括windows 7 64位)
  9. 小菜鸟vue入坑指南
  10. java课程之团队开发冲刺阶段1.7
  11. php如何按日期统计,关于按日获取统计信息:按日期获取统计信息 – 日期时间列 – mysql / php...
  12. OPPO R17引领渐变色手机潮流,15步技术处理工艺出众
  13. html图片从中间淡入淡出效果,CSS中的多个图像交叉淡入淡出-无需(java)脚本
  14. “芯”视野主题系列—— 加密芯片在医疗、美容行业内的应用
  15. 最新Java基础面试题及答案整理
  16. 二叉树前中后序遍历的非递归实现以及层次遍历、zig-zag型遍历详解
  17. 【渝粤教育】国家开放大学2018年秋季 2408T中国当代文学 参考试题
  18. DAY2_L2正则化
  19. 有了这些平面设计网站,可以为你提供免费素材和灵感
  20. Day3_Pytorch入门——人脸标点绘图(简单)

热门文章

  1. 【转】SpringCloud学习
  2. VMware下Linux配置局域网和外网访问(CentOS)
  3. [安全测试报告]针对某厂商的一次渗透性测试
  4. CUDA计算向量内积的程序(源自CUDA范例编程)
  5. 程序员应知道这十大面向对象设计原则
  6. SecureCRT恢复默认字体
  7. 使用C#进行图片转换格式,缩放,自动旋转,保留exif(转载)
  8. Could not reload resource bundles java.lang.NoS...
  9. 剑指 Offer II 109. 开密码锁
  10. 僵尸矩阵 · Zombie in Matrix