Number of processors/cores in command line
I think the method you give is the most portable on Linux. Instead of spawning unnecessary cat
and wc
processes, you can shorten it a bit:
$ grep --count ^processor /proc/cpuinfo
2
nproc
is what you are looking for.
More here : http://www.cyberciti.biz/faq/linux-get-number-of-cpus-core-command/
The most simplest tool comes with glibc and is called getconf
:
$ getconf _NPROCESSORS_ONLN
4