我正在尝试使用下面的 top 命令获取内存使用情况。
KiB Mem : 8009480 total, 1438848 free, 1964392 used, 4606240 buff/cache
KiB Swap: 7340028 total, 5302364 free, 2037664 used. 5202692 avail Mem
Run Code Online (Sandbox Code Playgroud)
top -p $PID -n 1 -b | grep 'KiB Mem :' | awk -F, '{print $3}'
1963780 used
Run Code Online (Sandbox Code Playgroud)
奇怪的是,有时我收到的输出为
*"15108960+used"*
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么有时会出现+
,符号。*
我在手册页中找不到有关它的任何内容。
这意味着什么?如何在输出中不包含命令并top
打印命令。*
+
注意:在 CentOs 机器上运行。
首先,top
这不是获取机器内存信息的好方法。该free
命令旨在用于获取内存信息。您也可以使用vmstat -s
.
现在,关于top
,我从未*
在摘要区域中看到过字符,但+
符号的解释出现在 的手册页中top(1)
:
If you see a `+' between a displayed number and the
following label, it means that top was forced to truncate
some portion of that number. By raising the scaling
factor, such truncation can be avoided.
Run Code Online (Sandbox Code Playgroud)
-E
您可以使用标志或交互式命令将缩放比例从 KiB 更改为其他值E
。
-E :Enforce-Summary-Memory-Scaling as: -E k | m | g | t | p | e
Instructs top to force summary area memory to be scaled as:
k - kibibytes
m - mebibytes
g - gibibytes
t - tebibytes
p - pebibytes
e - exbibytes
Later this can be changed with the `E' command toggle.
Run Code Online (Sandbox Code Playgroud)
例如,-Em
将缩放比例从 KiB 更改为 MiB。
但同样,如果你只是想获取内存信息,不要使用top
,使用free
.