this time it surely works on bsd

This commit is contained in:
Jonas Maier 2025-12-04 12:39:06 +01:00
parent 4303cf2e00
commit 90b26dc5e0
Signed by: jonas
SSH Key Fingerprint: SHA256:yRTjlpb3jSdw2EnZLAWyB4AghBPI8tu42eFXiICyb1U

View File

@ -14,11 +14,19 @@ get_mem_info() {
# macOS / BSD via sysctl
if command -v sysctl >/dev/null 2>&1; then
# total memory
mem_total=$(sysctl -n hw.memsize 2>/dev/null)
if [ -n "$mem_total" ]; then
# convert bytes → kB
mem_total=$(expr "$mem_total" / 1024)
mem_total_bytes=$(
sysctl -n hw.memsize 2>/dev/null || \
sysctl -n hw.realmem 2>/dev/null || \
sysctl -n hw.physmem 2>/dev/null || \
sysctl -n hw.physmem64 2>/dev/null
)
if [ -n "$mem_total_bytes" ] 2>/dev/null; then
mem_total=$(expr "$mem_total_bytes" / 1024) # convert to kB
else
mem_total=""
fi
# available memory varies by OS; fallback to inactive + free