linux命令查看cpu序列号,在Linux中使用C / C ++获取机器序列号和CPU ID

小编典典

这是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);

}

这篇Wikipedia文章中有关如何使用该CPUID指令的很好参考。

编辑 Wikipedia文章说,序列号是随Pentium

III一起引入的,但是由于隐私问题,以后的型号中不再使用该序列号。在Linux系统上,您可以通过执行以下操作检查此功能(PSN位)是否存在:

grep -i --color psn /proc/cpuinfo

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

2020-06-02

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值