Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discover number of *logical* cores on Mac OS X?

Tags:

macos

makefile

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.

VERY LATE EDIT: Just to clarify: I'm asking how many logical cores are available, because this corresponds with how many simultaneous jobs I want make to spawn. jkp's answer, further refined by Chris Lloyd, was exactly what I needed. YMMV.

like image 463
Mike DeSimone Avatar asked Nov 11 '09 14:11

Mike DeSimone


People also ask

How many logical cores do I have Mac?

To find the number of cores running inside your MacBook, simply click on the ever-present Apple logo on the upper left corner of the screen. Once you do, you will see the option 'About This Mac'. Click on that to reveal a popup. Go to the Support tab and click on Specifications.

How do you find the number of logical cores?

Press Ctrl + Shift + Esc to open Task Manager. Select the Performance tab to see how many cores and logical processors your PC has.

Does my Mac have multiple cores?

Go to Apple Menu (top right corner on your Mac) → About This Mac and click on the System Report... button. In the window that is presented, click on the Hardware item at the top in the left column. On the right, you can see the processor type and the number of cores present in it.

How do you check if all cores are working Mac?

To enable viewing in the Dock, choose View > Dock Icon, then select the Show CPU option you want to view. In the Activity Monitor app on your Mac, do any of the following: To view processor activity over time, click CPU (or use the Touch Bar).


2 Answers

You can do this using the sysctl utility:

sysctl -n hw.ncpu 
like image 111
jkp Avatar answered Sep 22 '22 21:09

jkp


Even easier:

sysctl -n hw.ncpu 
like image 29
mlbright Avatar answered Sep 23 '22 21:09

mlbright