使用Proc文件系统计算进程的内存 [英] Calculating memory of a Process using Proc file system

查看:93
本文介绍了使用Proc文件系统计算进程的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过从Proc文件系统中读取值在Perl中编写小型过程监视器脚本.现在,我能够使用/proc/[pid]/status /proc/[pid]/io 来获取线程数,进程状态,读写字节数 strong>文件.现在,我想计算一个进程的内存使用情况.搜索之后,我知道/proc/[pid]/statm 会出现内存使用情况.但是我仍然无法弄清楚该文件中需要哪些字段来计算内存使用情况.谁可以帮我这个事?提前致谢.

解决方案

您可能想要residentsize.来自 kernel.org .

  • 程序总大小
    • 这是整个程序,包括从未交换过的内容
  • 居民常驻集大小
    • 当前内存中的内容(不包括换出的页面)

I am writing small process monitor script in Perl by reading values from Proc file system. Right now I am able to fetch number of threads, process state, number of bytes read and write using /proc/[pid]/status and /proc/[pid]/io files. Now I want to calculate the memory usage of a process. After searching, I came to know memory usage will be present /proc/[pid]/statm. But I still can't figure out what are necessary fields needed from that file to calculate the memory usage. Can anyone help me on this? Thanks in advance.

解决方案

You likely want resident or size. From kernel.org.

  • size total program size
    • This is the whole program, including stuff never swapped in
  • resident resident set size
    • Stuff in RAM at the current moment (this does not include pages swapped out)

这篇关于使用Proc文件系统计算进程的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆