Linux: Correctly calculate memory usage
This commit is contained in:
parent
187dfe7a79
commit
49cdb2f95c
18
neofetch
18
neofetch
|
@ -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")
|
||||||
|
|
Reference in New Issue