Question or issue on macOS:
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:
Tested on preproduction MacBook Air and Mac mini systems with Apple M1 chip and 8-core GPU, as well as production 1.2GHz quad-core Intel Core i7-based 13-inch MacBook Air systems and 3.6GHz quad-core Intel Core i3-based Mac mini systems, all configured with 16GB RAM, 2TB SSD, and prerelease macOS Big Sur. Scores represent browsers that. How to Install macOS on a PC Using the Installation USB. After you have successfully created your macOS installation USB, you will need to remove it from your Mac and plug it into the PC that you want to turn into a Hackintosh. We don't have any change log information yet for version 1.17.603 of CCleaner for Mac. Sometimes publishers take a little while to make this information available, so please check back in a few days to see if it has been updated. Mar 09, 2011 Many users are aware of some boot commands for Mac OS X that provide different functionality for your system. The following is a more comprehensive list of the keyboard commands you know and many. Note: The headings on this list indicate the Macintosh System bundle names; the bullet points indicate the version of the System File included in that bundle. This is to make it clearer for people searching for specific bundle versions as opposed to System File versions. Finder File versions are not indicated. 1 Classic Mac OS 1.1 Macintosh System Software (0 - 0.3) 1.1.1 System File 1 1.1.2.
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.
How to solve this problem?
Solution no. 1:
You can do this using the sysctl utility:
Solution no. 2:
Even easier:
Solution no. 3:
This should be cross platform. At least for Linux and Mac OS X.
A little bit slow but works.
Solution no. 4:
To do this in C you can use the sysctl(3) family of functions:
Interesting values to use in place of 'hw.logicalcpu', which counts cores, are:
Solution no. 5:
system_profiler SPHardwareDataType
shows I have 1 processor and 4 cores.
However, sysctl disagrees:
Foot-to-ball N 1 Mac Os Update
https://soft-my.mystrikingly.com/blog/fairy-meltdown-mac-os. But sysctl appears correct, as when I run a program that should take up all CPU slots, I see this program taking close to 800% of CPU time (in top
):
Solution no. 6:
Solution no. 7:
Use the system_profiler | grep 'Cores'
command.
I have a:
Solution no. 2:
Even easier:
Solution no. 3:
This should be cross platform. At least for Linux and Mac OS X.
A little bit slow but works.
Solution no. 4:
To do this in C you can use the sysctl(3) family of functions:
Interesting values to use in place of 'hw.logicalcpu', which counts cores, are:
Solution no. 5:
system_profiler SPHardwareDataType
shows I have 1 processor and 4 cores.
However, sysctl disagrees:
Foot-to-ball N 1 Mac Os Update
https://soft-my.mystrikingly.com/blog/fairy-meltdown-mac-os. But sysctl appears correct, as when I run a program that should take up all CPU slots, I see this program taking close to 800% of CPU time (in top
):
Solution no. 6:
Solution no. 7:
Use the system_profiler | grep 'Cores'
command.
I have a:
MacBook Pro Retina, Mid 2012.
Processor: 2.6 GHz Intel Core i7
According to Wikipedia, (http://en.wikipedia.org/wiki/Intel_Core#Core_i7) there is no Core i7 with 8 physical cores so the Hyperthreading idea must be the case. Ignore sysctl
and use the system_profiler
value for accuracy. The real question is whether or not you can efficiently run applications with 4 cores (long compile jobs?) without interrupting other processes.
Running a compiler parallelized with 4 cores doesn't appear to dramatically affect regular OS operations. So perhaps treating it as 8 cores is not so bad. Blooming nightshade mac os.
Solution no. 8:
As jkp said in a comment, that doesn't show the actual number of physical cores. to get the number of physical cores you can use the following command:
Solution no. 9:
The following command gives you all information about your CPU
Solution no. 10:
Foot-to-ball N 1 Mac Os X
It wasn't specified in the original question (although I saw OP post in comments that this wasn't an option), but many developers on macOS have the Homebrew package manager installed. Realm of the ghost king mac os.
For future developers who stumble upon this question, as long as the assumption (or requirement) of Homebrew being installed exists (e.g., in an engineering organization in a company), nproc
is one of the common GNU binaries that is included in the coreutils
package.
N1 Vesti
If you have scripts that you would prefer to write once (for Linux + macOS) instead of twice, or to avoid having if
blocks where you need to detect the OS to know whether or not to call nproc
vs sysctl -n hw.logicalcpu
, this may be a better option.