diff --git a/explorer/cpu_cores b/explorer/cpu_cores index 10a2e5749..d83dfcb8f 100755 --- a/explorer/cpu_cores +++ b/explorer/cpu_cores @@ -35,18 +35,20 @@ in (macosx) sysctl -n hw.physicalcpu ;; - (openbsd) - sysctl -n hw.ncpuonline + (netbsd|openbsd) + # OpenBSD sysctl(8) always exits 0 (thus `grep .' to check for success) + /sbin/sysctl -n hw.ncpuonline 2>/dev/null | grep . \ + || /sbin/sysctl -n hw.ncpu ;; - (freebsd|netbsd) - PATH=$(getconf PATH) + (freebsd) sysctl -n hw.ncpu ;; (*) if test -r /proc/cpuinfo then - cores=$(grep -c -e '^processor[[:blank:]]*:' /proc/cpuinfo) - test $((cores)) -ge 1 && echo $((cores)) || echo 1 + cores=$(grep -c -e '^processor[[:blank:]]*:' /proc/cpuinfo || :) + test $((cores)) -gt 0 || cores=1 + printf '%u\n' "${cores}" fi ;; esac diff --git a/explorer/cpu_sockets b/explorer/cpu_sockets index 8dccf1901..39f98b265 100755 --- a/explorer/cpu_sockets +++ b/explorer/cpu_sockets @@ -28,15 +28,14 @@ in (macosx) system_profiler SPHardwareDataType | grep -F 'Number of Processors' | awk -F': ' '{print $2}' ;; + (netbsd) + ;; (*) if test -r /proc/cpuinfo then sockets=$(grep -e '^physical id[[:blank:]]*:' /proc/cpuinfo | sort -u | wc -l) - if test $((sockets)) -lt 1 - then - sockets=$(grep -c -e '^processor[[:blank:]]*:' /proc/cpuinfo) - fi - echo $((sockets)) + test $((sockets)) -gt 0 || sockets=1 + printf '%u\n' "${sockets}" fi ;; esac diff --git a/explorer/memory b/explorer/memory index 9162e3747..7338f6d7f 100755 --- a/explorer/memory +++ b/explorer/memory @@ -62,9 +62,17 @@ in (FreeBSD) sysctl -n hw.realmem | bytes2kib ;; - (NetBSD|OpenBSD) - # NOTE: This reports "usable" memory, not physically installed memory. - command -p sysctl -n hw.physmem | bytes2kib + (NetBSD) + # NOTE: This reports "usable" memory, not physically installed memory + # (on some architectures). + # + # hw.physmem64 is available on NetBSD >= 2.0 + /sbin/sysctl -n hw.physmem64 | bytes2kib + ;; + (OpenBSD) + # NOTE: This reports "usable" memory, not physically installed memory + # (on some architectures). + sysctl -n hw.physmem | bytes2kib ;; (SunOS) # Make sure that awk from xpg4 is used for the scripts to work @@ -81,10 +89,12 @@ in then # Use memory blocks if the architecture (e.g. x86, PPC64, s390) # supports them (they denote physical memory) - num_mem_blocks=$(cat /sys/devices/system/memory/memory[0-9]*/state | grep -cxF online) - mem_block_size=$(cat /sys/devices/system/memory/block_size_bytes) - - echo $((num_mem_blocks * 0x${mem_block_size})) | bytes2kib && exit + if num_mem_blocks=$(cat /sys/devices/system/memory/memory[0-9]*/state 2>/dev/null | grep -cxF online) + then + mem_block_size=$(cat /sys/devices/system/memory/block_size_bytes) + echo $((num_mem_blocks * 0x${mem_block_size})) | bytes2kib + exit 0 + fi fi if test -r /proc/meminfo then