Linux: Correctly calculate memory usage

This commit is contained in:
Dylan Araps 2016-10-23 11:03:46 +11:00
parent 187dfe7a79
commit 49cdb2f95c
1 changed files with 10 additions and 8 deletions

View File

@ -1174,16 +1174,18 @@ getgpu() {
getmemory() { getmemory() {
case "$os" in case "$os" in
"Linux" | "Windows") "Linux" | "Windows")
if grep -F "MemAvail" /proc/meminfo >/dev/null 2>&1; then # MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
mem=($(awk -F ':| kB' '/MemTotal|MemAvail/ {printf $2}' /proc/meminfo)) # Source: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716
memused="$((mem[0] - mem[1]))" while IFS=":" read -r a b; do
else case "$a" in
mem=($(awk -F ':| kB' '/MemTotal|MemFree|Buffers|Cached/ {printf $2}' /proc/meminfo) 0 0) "MemTotal") memused="$((memused+=${b/kB}))"; memtotal="${b/kB}" ;;
memused="$((mem[0] - mem[1] - mem[2] - mem[3]))" "Shmem") memused="$((memused+=${b/kB}))" ;;
fi "MemFree" | "Buffers" | "Cached" | "SReclaimable") memused="$((memused-=${b/kB}))" ;;
esac
done < /proc/meminfo
memused="$((memused / 1024))" memused="$((memused / 1024))"
memtotal="$((mem[0] / 1024))" memtotal="$((memtotal / 1024))"
;; ;;
"Mac OS X" | "iPhone OS") "Mac OS X" | "iPhone OS")