tags:

views:

180

answers:

2

Google is failing me, so I decided to ask here...

How can you tell, from the command line, how many cores are on the machine when you're running Mac OS X? On Linux, I use:

x=$(awk '/^processor/ {++n} END {print n+1}' /proc/cpuinfo)

It's not perfect, but it's close. This is intended to get fed to make, which is why it gives a result 1 higher than the actual number. And I know the above code can be written denser in Perl or can be written using grep, wc, and cut, but I decided the above was a good tradeoff between conciseness and readability.

+1  A: 
$ system_profiler | grep 'Total Number Of Cores'
kent
faster:$ system_profiler SPHardwareDataType | grep 'Total Number Of Cores'
kent
slower though if you include typing time
High Performance Mark
It's in a bash script; typing time is irrelevant.
Mike DeSimone
+5  A: 

You can do this using the sysctl utility:

sysctl hw.ncpu | awk '{print $2}'

jkp