c linux 获取cpuid_Linux下C编程 -- 得到系统的CPU信息(cpuid)
在 linux下可以通過查看 cat /proc/cpuinfo查看CPU的相關信息,但是在linux下C編程需要使用匯編語言來實現,因為C語言中沒有實現查看CPU信息的函數,一般實現如下:
(C中運行匯編用 __asm__等)
#include
#include
static inline void
get_cpuid(unsigned int i, unsigned int * buf)
{
unsigned int eax,ebx,ecx,edx;
__asm__ (
"cpuid"
:"=a"(eax),"=b"(ebx),"=c"(ecx),"=d"(edx):"a"(i));
buf[0]=eax;
buf[1]=ebx;
buf[2]=edx;
buf[3]=ecx;
}
int main()
{
unsigned int cpu[4];
get_cpuid(0,cpu);
}
需要清楚的是get_cpuid(i,buf)中i等于不同值,代表不同的含義:
0: Get vendor ID
1: Processor Info and Feature Bits,
3: Processor Serial Number
80000000h: Get Highest Extended Function Supported
80000001h: Extended Processor Info and Feature Bits
80000002h,80000003h,80000004h: Processor Brand String
具體訪問http://en.wikipedia.org/wiki/CPUID
總結
以上是生活随笔為你收集整理的c linux 获取cpuid_Linux下C编程 -- 得到系统的CPU信息(cpuid)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 友声电子秤设置软件_友声电子秤说明书/操
- 下一篇: linux c统计进程网络读写,linu