Linux内核机器ID,在Linux中使用C/C获取机器序列号和CPU ID

Here是Linux内核似乎使用的:

static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,

unsigned int *ecx, unsigned int *edx)

{

/* ecx is often an input as well as an output. */

asm volatile("cpuid"

: "=a" (*eax),

"=b" (*ebx),

"=c" (*ecx),

"=d" (*edx)

: "0" (*eax), "2" (*ecx));

}

哪一个可以使用,例如:

#include

int main(int argc, char **argv)

{

unsigned eax, ebx, ecx, edx;

eax = 1; /* processor info and feature bits */

native_cpuid(&eax, &ebx, &ecx, &edx);

printf("stepping %d\n", eax & 0xF);

printf("model %d\n", (eax >> 4) & 0xF);

printf("family %d\n", (eax >> 8) & 0xF);

printf("processor type %d\n", (eax >> 12) & 0x3);

printf("extended model %d\n", (eax >> 16) & 0xF);

printf("extended family %d\n", (eax >> 20) & 0xFF);

/* EDIT */

eax = 3; /* processor serial number */

native_cpuid(&eax, &ebx, &ecx, &edx);

/** see the CPUID Wikipedia article on which models return the serial

number in which registers. The example here is for

Pentium III */

printf("serial number 0x%08x%08x\n", edx, ecx);

}

编辑维基百科文章说,序列号是引入了奔腾III,但由于隐私问题,后来的模型中没有实施。在Linux系统上,您可以通过执行以下操作来检查此功能(PSN位)的存在:

grep -i --color psn /proc/cpuinfo

如果这不显示任何内容,您的系统不支持处理器序列号。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值