在系统文件/proc/cpuinfo记录了关于cpu的信息
processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Celeron(R) CPU 1005M @ 1.90GHz stepping : 9 microcode : 0x17 cpu MHz : 1200.000 cache size : 2048 KB physical id : 0 siblings : 2 core id : 0 cpu cores : 2 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms bogomips : 3791.83 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Celeron(R) CPU 1005M @ 1.90GHz stepping : 9 microcode : 0x17 cpu MHz : 1200.000 cache size : 2048 KB physical id : 0 siblings : 2 core id : 1 cpu cores : 2 apicid : 2 initial apicid : 2 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms bogomips : 3791.83 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management:
其中
process id是逻辑cpu的id
physical id是物理cpu的id
cpu cores是每个cpu的核数
因此
cat /proc/cpuinfo | grep "physical id" | uniq | wc -l #可以看出物理cpu的总个数。
cat /proc/cpuinfo | grep "cpu core" | uniq #可以看出每个cpu的核数。
cat /proc/cpuinfo | grep "processor" | wc -l #可以看出逻辑cpu的个数。