Last Updated: February 25, 2016
·
1.392K
· tim_yates

Find number of available processors from bash under OS X or Linux

I needed to find the number of cores from bash in a way that worked on both OS X and Linux systems.

After a bit of searching I came up with:

CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

Which seems to work well (well enough for my needs anyhow)