Last active
June 6, 2025 21:12
-
-
Save Flushot/e185e477467cfcfab25b14a365fa7aeb to your computer and use it in GitHub Desktop.
Get logical CPU count in a platform-independent way
This file contains hidden or 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 | |
os="$(uname -s)" | |
case $os in | |
Darwin*|BSD*) sysctl -n hw.ncpu;; # macOS, BSD | |
Linux*) nproc --all;; # Linux | |
Solaris*) psrinfo -p;; # Solaris | |
Win*|CYGWIN*|MINGW*|MSYS_NT*) echo "$NUMBER_OF_PROCESSORS";; # Windows | |
*) >&2 echo "unsupported os: $os"; exit 1;; # Unsupported | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment