Koten
Koten

Reputation: 689

Get CPU model name on Linux without parsing /proc/cpuinfo

I want to get CPU name on linux using C without parsing /proc/cpuinfo, I actually want the code that writes the data to /proc/cpuinfo, Thanks.

Upvotes: 1

Views: 2001

Answers (2)

falstaff
falstaff

Reputation: 3693

As dreamlax already mentions, cpuinfo is a file provided by the virtual filesystem procfs, hence a read system call is the way to read the information directly from the kernel.

There is also the system call uname which provides a hardware identifier (machine)...

Upvotes: 0

dreamlax
dreamlax

Reputation: 95355

/proc/cpuinfo is not a real file, it only exists as part of the procfs file system (which is virtual). The code responsible for producing this virtual file is part of the Linux kernel. See here.

For x86 CPUs for example, you can have a look at how this file is generated here.

Upvotes: 1

Related Questions