如何检查进程的(绝对)内存使用情况?
How to check the (absolute) memory usage of a process?
我有一个服务器进程 运行 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 上运行该进程,所以我希望(终端)进程显示在Activity 监视器使用 ~19 GB 内存。然而,终端进程 运行ning 离那个还差得很远(它们最多 ~900 Mb)。
有什么方法可以获取内存使用量的绝对值(以 Mb 为单位)?或者,如何确定用于此计算的“机器上的物理内存”?
要将 Nate Eldredge 的评论转换为答案,首先,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 的估计非常吻合。
我有一个服务器进程 运行 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 上运行该进程,所以我希望(终端)进程显示在Activity 监视器使用 ~19 GB 内存。然而,终端进程 运行ning 离那个还差得很远(它们最多 ~900 Mb)。
有什么方法可以获取内存使用量的绝对值(以 Mb 为单位)?或者,如何确定用于此计算的“机器上的物理内存”?
要将 Nate Eldredge 的评论转换为答案,首先,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 的估计非常吻合。