Skip to content

Instantly share code, notes, and snippets.

@jcttrll
Created February 19, 2024 13:12
Show Gist options
  • Save jcttrll/42cf3e09850eed64e5d0aa4918e30564 to your computer and use it in GitHub Desktop.
Save jcttrll/42cf3e09850eed64e5d0aa4918e30564 to your computer and use it in GitHub Desktop.
Pure Bash CPU/core/thread count from /proc/cpuinfo
#!/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