Reputation: 3689
How do I get the # of logical CPUs in zsh or bash? I want to create a makep alias that passes the # of cpus to 'make -j'.
Upvotes: 1
Views: 946
Reputation: 55
The simpelst solution is to call "nproc" which just returns the number of logical cores
nproc --all give you all installed processors (on openvz this returns the cpus of the system, not of the maybe limited number in your container!)
nproc without any option gives you the number of cores available to the current process (so bash or zsh in your case) nproc is part of coreutils.
No need to grep :)
For more info see "man nproc"
HTH
Upvotes: 0
Reputation: 360305
For Linux:
grep -c proc /proc/cpuinfo
The shell doesn't matter. This will work in any.
Upvotes: 4