Linux: HOWTO get the number of CPUs

Posted by Harald Hoyer on 13 November 2013

returns the number of CPUs online.

Internally it is parsing /sys/devices/system/cpu/online, which can have the contents: 0-3,5,7-9.

Better let getconf do all the counting for you.

This is very useful, if you want to optimize the number of threads.