The command psrinfo -pv
is the command you are looking for. It gives you the number of physical cpus plus the count of virtual processor per physical processor.
For example on a V880 it looks like this:
The physical processor has 1 virtual processor (0)
UltraSPARC-III+ (portid 0 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (1)
UltraSPARC-III+ (portid 1 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (2)
UltraSPARC-III+ (portid 2 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (3)
UltraSPARC-III+ (portid 3 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (4)
UltraSPARC-III+ (portid 4 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (5)
UltraSPARC-III+ (portid 5 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (6)
UltraSPARC-III+ (portid 6 impl 0x15 ver 0x23 clock 900 MHz)
The physical processor has 1 virtual processor (7)
UltraSPARC-III+ (portid 7 impl 0x15 ver 0x23 clock 900 MHz)
Hope that helps. :-)
EDIT
A multicore machine has e.g. this output
The physical processor has 4 virtual processors (0-3)
SPARC64-VI (portid 1024 impl 0x6 ver 0x93 clock 2150 MHz)
The physical processor has 4 virtual processors (8-11)
SPARC64-VI (portid 1032 impl 0x6 ver 0x93 clock 2150 MHz)
On a Big Endian-System (Solaris on SPARC)
$ echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6
0
On a little endian system (Linux on x86)
$ echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6
1
The solution above is clever and works great for Linux *86 and Solaris Sparc.
I needed a shell-only (no Perl) solution that also worked on AIX/Power and HPUX/Itanium. Unfortunately the last two don't play nice: AIX reports "6" and HPUX gives an empty line.
Using your solution, I was able to craft something that worked on all these Unix systems:
$ echo I | tr -d [:space:] | od -to2 | head -n1 | awk '{print $2}' | cut -c6
Regarding the Python solution someone posted, it does not work in Jython because the JVM treats everything as Big. If anyone can get it to work in Jython, please post!
Also, I found this, which explains the endianness of various platforms. Some hardware can operate in either mode depending on what the O/S selects: http://labs.hoffmanlabs.com/node/544
If you're going to use awk this line can be simplified to:
echo -n I | od -to2 | awk '{ print substr($2,6,1); exit}'
For small Linux boxes that don't have 'od' (say OpenWrt) then try 'hexdump':
echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}'
Best Answer
On OpenBSD you have:
or
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.