【问题标题】:How to check the (absolute) memory usage of a process?如何检查进程的(绝对)内存使用情况?
【发布时间】:2021-03-03 23:47:58
【问题描述】:

我有一个使用 pid 24257 运行的服务器进程,并且想知道它正在使用多少内存(以估计在 Kubernetes 中为同一进程分配多少资源)。根据ps (https://man7.org/linux/man-pages/man1/ps.1.html) 的手册页,这可以通过%mem 输出格式说明符获得:

       %mem        %MEM      ratio of the process's resident set size
                             to the physical memory on the machine,
                             expressed as a percentage.  (alias pmem).

如果我运行它,我会得到

> ps -p 24257 -o %mem
%MEM
 0.3

我不确定我是否理解此输出,因为我在具有 64 GB 内存的 MacBook Pro 上运行该进程,所以我希望(终端)进程在活动监视器中显示为使用 ~19 GB 内存。但是,正在运行的终端进程远不及这一点(它们最多约为 900 Mb)。

有没有办法可以将内存使用量作为绝对数(以 Mb 为单位)?否则,我如何确定用于此计算的“机器上的物理内存”?

【问题讨论】:

  • 64GB 的 0.3% 是 192 MB,而不是 19 GB。
  • 无论如何,如果驻留集大小是您所说的“内存使用”(还有其他可能的概念),那么ps/proc/PID/status 中都有一个RSS 字段

标签: memory memory-management ps


【解决方案1】:

要将Nate Eldredge的cmets转换为答案,首先0.3的输出是一个百分比,所以64 GB的0.3%就是192 MB。

其次,rss 输出应该给出驻留集的大小:

       rss         RSS       resident set size, the non-swapped physical
                             memory that a task has used (in kilobytes).
                             (alias rssize, rsz).

运行此命令给出

> ps -p 24257 -o %mem,rss
%MEM    RSS
 0.3 209908

~21 Mb 的输出与%MEM 输出的~19 Gb 估计值非常吻合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多