免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1817 | 回复: 2
打印 上一主题 下一主题

[系统管理] 如何统计一个进程打开的文件个数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-01-24 19:21 |只看该作者 |倒序浏览
本帖最后由 sendltd 于 2014-01-24 19:35 编辑

查看某进程打开的文件个数用哪个命令?

  1. ls -l /proc/<pid>/fd | wc -l
  2. lsof -n -p <pid> | wc -l
复制代码
这两个结果差老远了,分别代表什么?哪个才是对的?
(lsof有重复的,即使去掉重复的,也比/proc/<pid>/fd多)

论坛徽章:
15
射手座
日期:2014-02-26 13:45:082015年迎新春徽章
日期:2015-03-04 09:54:452015年辞旧岁徽章
日期:2015-03-03 16:54:15羊年新春福章
日期:2015-02-26 08:47:552015年亚洲杯之卡塔尔
日期:2015-02-03 08:33:45射手座
日期:2014-12-31 08:36:51水瓶座
日期:2014-06-04 08:33:52天蝎座
日期:2014-05-14 14:30:41天秤座
日期:2014-04-21 08:37:08处女座
日期:2014-04-18 16:57:05戌狗
日期:2014-04-04 12:21:33技术图书徽章
日期:2014-03-25 09:00:29
2 [报告]
发表于 2014-01-26 09:02 |只看该作者
proc中应该只包含了进程中fd为数字的(通常open打开)的文件,而lsof中包含了所有包括mmap的文件,当前工作目录等
       FD         is the File Descriptor number of the file or:

                       cwd  current working directory;
                       Lnn  library references (AIX);
                       err  FD information error (see NAME column);
                       jld  jail directory (FreeBSD);
                       ltx  shared library text (code and data);
                       Mxx  hex memory-mapped type number xx.
                       m86  DOS Merge mapped file;
                       mem  memory-mapped file;
                       mmap memory-mapped device;
                       pd   parent directory;
                       rtd  root directory;
                       tr   kernel trace file (OpenBSD);
                       txt  program text (code and data);
                       v86  VP/ix mapped file;

论坛徽章:
0
3 [报告]
发表于 2014-01-26 14:06 |只看该作者
Thanks. 受老外的这篇文章的误导,http://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html
所以发帖一问,其实man lsof就知道老外说错了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP