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)
Written by Tim Yates
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Osx
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#