How to count the number of processors on an OpenBSD system

central-processing-unitopenbsd

How can I determine the number of CPUs on an OpenBSD system, using either system tools or C code?

The technique I know of to count CPUs on other BSD platforms — checking /var/run/dmesg.boot for certain strings, doesn't always seem to work.

More context: Unfortunately, I don't have an OpenBSD system available to play around with. I am trying to address the OpenBSD-specific test failures for a Perl module.

Best Answer

On OpenBSD you have:

sysctl hw.ncpu

or

sysctl hw.ncpufound

As explained in sysctl(3), ncpu is the number of CPU used by system and ncpufound is the number of CPU found by the system.

By the way, devio.us provides free shell account on OpenBSD servers.