Created
February 19, 2024 13:12
-
-
Save jcttrll/42cf3e09850eed64e5d0aa4918e30564 to your computer and use it in GitHub Desktop.
Pure Bash CPU/core/thread count from /proc/cpuinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eE | |
main() { | |
local -A physicalIds coreIds | |
local count=0 | |
local name _ value | |
while IFS=$' \t' read -r name _ value; do | |
case "$name" in | |
processor) count=$((count + 1)) ;; | |
physical) physicalIds["$value"]=1 ;; | |
core) coreIds["$value"]=1 ;; | |
esac | |
done </proc/cpuinfo | |
echo "${#physicalIds[@]} cpu(s), ${#coreIds[@]} core(s), $count thread(s)" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment