How frequently is the proc
file system updated on Linux? Is it 20 milliseconds (time quantum)?
-
1+1. This is a great homework question to ask students. Thanks.– Jonathan Ben-AvrahamMay 5, 2013 at 0:19
-
5@JonathanBen-Avraham Feel free to ask on meta whether the community allows you to create a "great homework" tag... 8-)– Hauke LagingMay 5, 2013 at 0:22
-
1See also What happens when I run the command cat /proc/cpuinfo?– Gilles 'SO- stop being evil'Feb 23, 2016 at 23:04
2 Answers
The information that you read from the proc filesystem is not stored on any media (not even in RAM), so there is nothing to update.
The purpose of the proc file system is to allow userspace programs to obtain or set kernel data using the simple and familiar file system semantics (open
, close
, read
, write
, lseek
), even though the data that is read or written doesn't reside on any media. This design decision was deemed better (e.g. human readable and easily scriptable) for getting and setting data whose format could not be specified in advance than implementing something such as ASN1 encoded OIDs, which also would have worked fine.
The data that you see when you read from the proc filesystem is generated on-the-fly when you do a read from the begining of a file. That is, doing the read causes the data to be generated by a kernel callback function that is specific to the file you are reading. Doing an lseek
to the begining of the file and reading again causes another call to the callback that generates the data again. Similarly, when you write to a writable file in the proc filesystem, a callback function is called that parses the input and sets kernel variables. The input data in it's raw form isn't stored.
The above is just a slightly more verbose way of saying what Hauke Laging states so succinctly. I suggest that you accept his answer.
-
If you need proof that this answer is true, try to run inotify on a "file" or directory in /proc (or /sys for that matter) ... its too bad, it would make udev completely unneeded if you could just tell a simple inotify process to run x when something appears in y May 5, 2013 at 3:42
It is updated on every access. You see the state of the kernel in that moment. That's why the size shown for the "files" is not the real size. The real size can change and is determined the moment you access the file.
You could say, it may be not updated for days. If you don't look at it. :-)
-
11+1. It's a little like the saying, "If a tree falls in a forest and no one is around to hear it, does it make a sound?", i.e. "If there is a proc file system and no one reads it, does it exist?". May 5, 2013 at 0:08
-
@JonathanBen-Avraham You could say that about every FS, couldn't you? :-) But bear in mind that there are far more accesses to proc than one would guess. Comment it out in fstab, reboot, and all hell breaks loose... May 5, 2013 at 0:20
-
What I meant was that the data in a media-backed file system exists even when no one reads it at any particular moment. It doesn't come into existence at the moment of reading like proc and sys. You are correct, proc has a lot of readers. However, sys is a similar filesystem that you can comment out of fstab, at least on smaller systems and still run Ok. Cheers. May 5, 2013 at 0:27
-
4So is the cat dead or not? Take a look and see. It's dead Jim. Poor cat. May 5, 2013 at 7:22
-