The files are not stored on disk, but they are hooks to the kernel.
When you open a file (using fopen()
), the kernel handles this job. It walks through the mountpoints, finds the apropriate driver to handle the request, and hands the task to that driver.
In the case of /proc
, the file read request is passed to the internal "proc" system in the kernel. At the moment you read the file, it returns the value from memory.
A similar pattern also happens with the files in /dev
. The kernel sees you open a dev-node with a certain device ID, and associates the IO stream with a particular driver that handles the request.
Basically I would like to constantly get updated values from meminfo and cpuinfo.
You can read the proc filesystem to read these values, or see if there are maybe other syscalls you can use for it. It will be a polling mechanism nevertheless, so there is always a certain system load involved.