osxcross/tools/get_cpu_count.sh

20 lines
445 B
Bash
Raw Normal View History

#!/usr/bin/env bash
#
2016-09-22 19:14:50 +02:00
# Print the number of enabled CPUs by either using nproc or ncpus.
# If both commands fail, fall back to a platform-independent C++ solution.
# If that also fails, just echo 1...
#
2016-09-22 19:14:50 +02:00
pushd "${0%/*}" &>/dev/null
2016-09-22 19:14:50 +02:00
nproc 2>/dev/null && exit 0 || ncpus 2>/dev/null && exit 0 || {
if [ ! -f cpucount ]; then
c++ cpucount.cpp -std=c++0x -o cpucount &>/dev/null || { echo 1 && exit 0; }
fi
}
2016-09-22 19:14:50 +02:00
./cpucount
2016-09-22 19:14:50 +02:00
popd &>/dev/null