The Informations about the processor you could extract from /proc/cpuinfo.
To get the Serial Number you should have a look at dmidecode. I didn't look in there right now, but dmidecode is able to show you the serial number, so i would start there.
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));
}
which one then can use as e.g.:
#include <stdio.h>
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);
}
Where a good reference on how to use the CPUID instruction is in this Wikipedia article.
EDIT The Wikipedia article says that the serial number was introduced with the Pentium III but was not anymore implemented in later models due to privacy concerns. On a Linux system you can check for the presence of this feature (PSN bit) by doing:
grep -i --color psn /proc/cpuinfo
if this does not show anything, your system does not support a processor serial number.
There is a cpuinfo.h include in GCC. It is safe, use it.
Sample (I have GCC 4.7+ and feel happy of using "auto" here):
Output:
The Informations about the processor you could extract from
/proc/cpuinfo
.To get the Serial Number you should have a look at
dmidecode
. I didn't look in there right now, butdmidecode
is able to show you the serial number, so i would start there.This program will help you run Linux commands programmatically:
API usage:
GetSystemOutput("/usr/bin/lsb_release -a")
And following the commands:
Here is what the Linux kernel seems to use:
which one then can use as e.g.:
Where a good reference on how to use the
CPUID
instruction is in this Wikipedia article.EDIT The Wikipedia article says that the serial number was introduced with the Pentium III but was not anymore implemented in later models due to privacy concerns. On a Linux system you can check for the presence of this feature (PSN bit) by doing:
if this does not show anything, your system does not support a processor serial number.