[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: getloadavg and proc filesystem



Hi Nelson


On Oct 4, 2005, at 9:06 PM, Nelson Castillo wrote:
Hi, it shouldn't happen for getloadavg.

....


it expects to be able to write all of its data at once.
(it uses sprintf and not snprintf).


IMHO sprintf is not atomic - and thus a context switch at the wrong time
will provide you with broken data...


When you read from /proc, the kernel calls a callback.
The callback writes the data to a buffer and then the function
ends. So, when you open the file in user space,
the kernel will write most of the data to the buffer,
and if the statistics change, you will still reference the
data written by the callback.

If I do an seek however back to the start of the file, I get
new data - so either the proc filesystem is clever enough to
hold a cache for every open file or I can't see how I can
avoid getting half of one file, and half of another....


Something might happen if the /proc entry is big.
In this case, things get more complicated and
I still don't understand the details. I'm a newbie.


The size of the file should make no difference upon whether it works
or not, just how often it breaks (if it is indeed broken)...

Looks like I will have to go ask the kernel mailing list...

Andrew




Reply to: