- Is it possible to use
lseek(fd,0) and then read(fd,buf) for the /proc/stat file instead of opening it again so that the next time I get the updated contents of this file? - And what causes the
mmap() call after opening this file (see below)?
The problem I am facing is that the top reports are too low for CPU usage (10% versus 100% for software interrupts). Sagittarius indicates that the vertex does not reopen this file, but instead looks at the beginning and reads it again. And somehow, the content that is read from this file the next time does not match what I get when I run cat only for the /proc/stat file.
In addition, if I run top and cat /proc/stat in a loop at the same time, then top starts reporting the correct CPU usage.
Another difference is that top uses the mmap() call immediately after opening the /proc/stat file, and cat does not. I'm not sure if this could also be due to my problem (because filesdes=-1 here):
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7b37649000
I am using Ubuntu 10.04.1 Desktop edition with image of 2.6.32-27 server. Intel Q6600 processor.
linux cpu-usage procfs seek
Hans solo
source share