Number of physical and virtual processors

Hi,

i am trying to find out hpw many virtual and physical processors does any linux machine has:
output of /proc/cpuinfo is as below :

 
[root@VM172016001139 etc]# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 26
model name      : Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
stepping        : 4
cpu MHz         : 2933.437
cache size      : 12288 KB
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm
bogomips        : 5866.87
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management: [8]

using this info how can i figure out how many physical or virtual processor does any linux machine has...is der any better way to find out or any small script

grep processor /proc/cpuinfo

Logical:

grep '^processor' /proc/cpuinfo

Physical:

awk '/^physical id/ && s[$NF]++==0' /proc/cpuinfo

Cores:

awk -F: '/^physical id/ {ph=$NF} /^core id/ && a[ph,$NF]++==0' /proc/cpuinfo

Pipe each to wc -l to get the number!

It is easy to find the number and type of physical processors.

What do you mean by virtual processors? As in virtual machines?

From the earlier posts, I'm assuming by virtual processors OP means processor threads.

lscpu

Thanks a lot "MadeInGermany"...Could u please send me the output of below script which is used to find the number of physical processor of machine :

 
awk '/^physical id/ && s[$NF]++==0' /proc/cpuinfo

i only have virtual machines..so i just want to know how the output looks on physical machine

in fact for all the three commands output on physical machine

Actually, from a vm guest, this can be quite difficult. I mean, in most cases for most all hypervisor, any and all CPUs are virtual. The actually allocation given to a VM is often times only known to the hypervisor host itself and not to the guest.

On a physical box, it all depends.

If you have contemporary CPUs, and you have a relatively contemporary Linux, /proc/cpuinfo will likely show what you want. However, if you have older CPUs and/or older Linux, the information could be very inaccurate.

In your case, and this is a guess, looks like you've been assigned one virtual CPU.... what that means though, isn't well defined.

This is a system with 1 physical CPU, quad-core:

% grep '^processor' /proc/cpuinfo
processor       : 0
processor       : 1
processor       : 2
processor       : 3
% awk '/^physical id/ && s[$NF]++==0' /proc/cpuinfo
physical id     : 0
% awk -F: '/^physical id/ {ph=$NF} /^core id/ && a[ph,$NF]++==0' /proc/cpuinfo
core id         : 0
core id         : 1
core id         : 2
core id         : 3