Saya mencoba menulis skrip untuk memonitor status memori. Inilah yang saya miliki sejauh ini:
# 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))"
Saya hanya bereksperimen di sini, jadi ini bukan skrip final. Tapi saya tidak bisa mendapatkan angka dari sini dan monitor Aktivitas cocok. Sebagai contoh, Active + Wired memory di sini menunjukkan 9 GB di komputer saya, sementara Monitor aktivitas mengklaim itu hanya 6,5 GB. Pembacaan memori berkabel cocok, tetapi tidak dengan pembacaan aktif. Apa yang kulewatkan di sini?