OSX vm_stat 和 Activity Monitor.app 的内存读数不一致

OSX vm_stat 和 Activity Monitor.app 的内存读数不一致

我正在尝试编写一个脚本来监控内存状态。以下是我目前所做的事情:

# Memory Usage
ramactive=$(vm_stat | grep "Pages active" | while read a b c; do echo "$((${c%?}*4096/1024/1024))"; done)
ramwired=$(vm_stat | grep "Pages wired" | while read a b c d; do echo "$((${d%?}*4096/1024/1024))"; done)
ramspec=$(vm_stat | grep "Pages speculative" | while read a b c; do echo "$((${c%?}*4096/1024/1024))"; done)
raminactive=$(vm_stat | grep "Pages inactive" | while read a b c; do echo "$((${c%?}*4096/1024/1024))"; done)
ramfree=$(vm_stat | grep "Pages free" | while read a b c; do echo "$((${c%?}*4096/1024/1024))"; done)
rampurge=$(vm_stat | grep "Pages purgeable" | while read a b c; do echo "$((${c%?}*4096/1024/1024))"; done)

printf "RAM\n"
printf "%-11s%'.f MB Used\n" "Active:" "$ramactive"
printf "%-11s%'.f MB Used\n" "Wired:" "$ramwired"

printf "%-11s%'.f MB Used\n" "Inactive:" "$raminactive"
printf "%-11s%'.f MB Used\n" "Spec:" "$ramspec"
printf "%-11s%'.f MB Used\n" "Cached:" "$(($ramspec+$raminactive))"

printf "%-11s%'.f MB Used\n" "Free:" "$ramfree"

printf "%-11s%'.f MB Used\n" "Total Used:" "$(($ramwired+$ramactive))"
printf "%-11s%'.f MB Used\n" "Used-Purge:" "$(($ramwired+$ramactive-$rampurge))"
printf "%-11s%'.f MB Used\n" "Total Free:" "$(($ramfree+$ramspec+$raminactive))"
printf "%-11s%'.f MB Used\n" "Total RAM:" "$(($ramactive+$ramwired+$ramspec+$raminactive+$ramfree))"

我只是在这里进行实验,所以这不是最终的脚本。但我无法让这里的数字和活动监视器相匹配。例如,这里的活动 + 有线内存在我的计算机上显示为 9 GB,而活动监视器声称它只有 6.5 GB。有线内存读数匹配,但活动读数不匹配。我这里遗漏了什么?

相关内容