Linux – Under what circumstances, if any, will the result of reading /proc/cpuinfo change

cpulinux-kernelproc

What I understand so far is that when a program opens and reads any file under /proc/, the kernel will generate the information on the fly. In the specific case of cpuinfo most of that data is determined by hardware and obviously is not going to change while the system is running. What I am not sure of is whether all of that data cannot change while the system is running.

Is it possible for any of the values returned from /proc/cpuinfo to be changed without the system having to be restarted?

Best Answer

Yes. For one thing, the cpu MHz field will change very often since it shows the current speed of your CPU. For example, on my system:

$ for i in {1..10}; do grep -m 1 MHz /proc/cpuinfo ; done
cpu MHz     : 1596.000
cpu MHz     : 1596.000
cpu MHz     : 1596.000
cpu MHz     : 1596.000
cpu MHz     : 2394.000
cpu MHz     : 2394.000
cpu MHz     : 1596.000
cpu MHz     : 1596.000
cpu MHz     : 2394.000
cpu MHz     : 2394.000

The command above will print the cpu MHz line of my first CPU 10 times. As you can see above, that resulted in 2 separate values, and this without even adding any wait time. You can expect this field to change very often. I don't think any of the other values are likely to change and none did in my tests but I can't swear to that.

Related Question