Re: getloadavg and proc filesystem
On Tuesday 04 October 2005 12:27 pm, sin wrote:
> Andrew Miehs wrote:
> > Actually, I am looking at /proc/stat and that is the problem...
> > I looked at the implementation of getloadavg to see how 'real
> > programmers' used
> > the proc filesystem. I do not see how the implementation (in glibc) is
> > protected
> > from the kernel changing the data underneath it while it is being
> > read....
> > ie: getloadavg open /proc/loadavg for O_RDONLY
> > getloadavg reads the first 4 bytes
> > kernel completely updates the file
> > getloadavg reads the rest of file.....
> > And as /proc/stat is bigger, the problem is likely to occur even more
> > often?!
> > Or am i just being stupid?
> Not a kernel guru, but to get that kind of situation, your program
> should run awfully slow. When you read from proc you read directly from
> memory and from what I know, when you open a file in proc it stays the
> same for you until you close it (but I might be wrong)
unless that's changed in 2.6, the file did change on you even when you had it
open in 2.4. i wrote a program once that did an
to collect data from /proc and it worked just fine.