I wonder how to get how many cores (including emulated via HT and such) are avaliable to user via bash shell-script command?

  • On what operating system? – Mat Jan 15 '12 at 8:44
  • Debian, Ubuntu, OpenSuse, MacOsX – myWallJSON Jan 15 '12 at 9:25

On Linux:

grep ^processor /proc/cpuinfo | wc -l
  • 7
    Or try grep -c ^processor /proc/cpuinfo and you won't need to spawn two processes. – Alexios Jan 15 '12 at 10:36

You can also use nproc or nproc --all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.