I am running the following command to get the number of processors/cores in Linux:
cat /proc/cpuinfo | grep processor | wc -l
It works but it does not look elegant. How would you suggest improve it ?
I am running the following command to get the number of processors/cores in Linux:
cat /proc/cpuinfo | grep processor | wc -l
It works but it does not look elegant. How would you suggest improve it ?
If you need an os independent method, works across Windows and Linux. Use python
nproc
is what you are looking for.More here : http://www.cyberciti.biz/faq/linux-get-number-of-cpus-core-command/
On newer kernels you could also possibly use the the
/sys/devices/system/cpu/
interface to get a bit more information:See the official docs for more information on what all these mean.
If you want to do this so it works on linux and OS X, you can do: