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


4

我正在尝试编写一个脚本来监视内存状态。这是我到目前为止:

# 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))"

我只是在这里试验,所以这不是最后的剧本。但我无法从这里得到数字和活动监视器匹配。例如,Active + Wired内存在我的计算机上显示为9 GB,而Activity监视器声称它只有6.5 GB。有线内存读数匹配,但不是活动读数。我在这里错过了什么?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.