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

Re: getloadavg and proc filesystem

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)

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply to: