LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How often do Linux /proc files update? (https://www.linuxquestions.org/questions/linux-newbie-8/how-often-do-linux-proc-files-update-741438/)

Aztral 07-20-2009 11:17 AM

How often do Linux /proc files update?
 
I am wondering how often do the /proc/stat, /proc/meminfo/, /proc/pid/stat etc. files get rewritten?

Thanks

thewebhostingdir 07-20-2009 11:26 AM

Do you mean how offenly it gets updated? if this is the case then please note that it will give you real time results.

Simon Bridge 07-20-2009 11:31 AM

depends - some more than others.

eg.
cat /proc/acpi/thermal_zone/THRM/temperature

wait a bit and do it again.

What is your concern?

Learn about /proc
http://www.linux.com/archive/feature/126718

i92guboj 07-20-2009 11:31 AM

/proc is not a real fs, it doesn't exist in your disk.

It's rather a virtual fs which holds an image of the kernel structures that live in your memory. Hence, it's alive.

Aztral 07-20-2009 11:59 AM

I ask because I'm writing a program to do things like calculate cpu usage, memory usage etc. If, for example, I'm calculating CPU usage and doing so by parsing /proc/stat every so often, I wouldn't want to parse it twice in a time frame that didn't allow it to update. Since it's a file I just assumed it would only be re written to so often.

Is that assumption wrong?

Thanks for the responses, and thanks for that link Simon.

EDIT: Ok, so as I understand it these files are only actually created when you attempt to read them, meaning they are updated every time I try to read them regardless of how fast I do it? If this is the case, is there a max rate at which I should try to do so?

Simon Bridge 07-20-2009 12:12 PM

You know, you have access to the source code for all free-software programs. There are many programs that already do what you want. Instead of agonising in a vaccuum over how to program something, what policies to use, why not take a look at what another programmers have done and see if there is a pattern. You learn more that way.

i92guboj 07-20-2009 12:19 PM

It really depends but usually, for a system monitor, checking more than once a second -at most- doesn't make much sense. You can look at gkrellm or htop for a starter (the later will be easier to dig into probably).

And yep, the info from /proc is supplied on demand.

Aztral 07-20-2009 12:25 PM

Thanks guys. I have looked at some source for top, I know I'm kind of reinventing the wheel here but top just gives a lot of information I don't really need. I thought I'd simplify things a bit. But I will definitely look at a few more and look for some consistencies.

Thanks again.

Simon Bridge 07-21-2009 12:36 AM

An interesting one to look at is conky - which is more modular.
There are also applets for the panels which do simple system monitoring.

However, you were interested in the timings - look for how often top etc update the graphs for different resources and you'll get an idea of what you can do. This provides a starting point for experimentation. The important lesson here is "how to read source code" ... you have to learn to parse the code for the information you want. Then focus down on methods.

That's probably the most important skill you can take away from this.

Aztral 07-21-2009 11:20 AM

Quote:

Originally Posted by Simon Bridge (Post 3614734)
An interesting one to look at is conky - which is more modular.
There are also applets for the panels which do simple system monitoring.

However, you were interested in the timings - look for how often top etc update the graphs for different resources and you'll get an idea of what you can do. This provides a starting point for experimentation. The important lesson here is "how to read source code" ... you have to learn to parse the code for the information you want. Then focus down on methods.

That's probably the most important skill you can take away from this.

Thanks.

I definitely agree... reading some of this source code is not particularly easy for me.

jeromeNP7 07-21-2009 04:49 PM

The /proc files are not really files, it's rather some information provided by the system in a way that it can be accessed by functions and routines normally used to read files. So updating is not the proper term. If a value from a /proc doesn't change (for example because it simply remains the same), then there is no way telling if the system is still showing some cached value or if it has been retrieved again. Your application should determine for itself how often certain values are required to be displayed. I would even suggest to keep create a new report based on the /proc/<any-tool> value only if the user is not idle - it's a waste of system resources to report something every second, when obviously no one is in front of the PC and the screensaver already has taken over.

Linux

sundialsvcs 07-21-2009 09:06 PM

/proc is a "file system" (procfs) that is implemented entirely by the Linux kernel. In other words... each time you request "a list of files," and each time you open, read, or write to one of the "files" that you find, no physical I/O operation is actually taking place. Instead, the Linux kernel itself is serving-up everything that you see, in real time.

For instance, if you do ls /proc, every one of the "directories" that appear, whose name is a number, actually correspond to a process that existed at that particular instant in time. The "files" in that "directory" (may...) allow you to browse through information about that process.

The information that you see is always "atomically accurate," but it's also "constantly changing." For instance, if your file-listing says that there's a "file" named 123456, a millisecond later you might try to open that "file" and discover that it no longer exists: "process #123456 happens to be gone now... it vanished half-a-millisecond ago... deal with it."

thewebhostingdir 07-22-2009 10:08 AM

I agree with this
 
Quote:

Originally Posted by Simon Bridge (Post 3614734)
An interesting one to look at is conky - which is more modular.
There are also applets for the panels which do simple system monitoring.

However, you were interested in the timings - look for how often top etc update the graphs for different resources and you'll get an idea of what you can do. This provides a starting point for experimentation. The important lesson here is "how to read source code" ... you have to learn to parse the code for the information you want. Then focus down on methods.

That's probably the most important skill you can take away from this.

I also agree with this ....

Aztral 07-22-2009 11:11 AM

Thanks jerome and sundial. It makes sense to me now. Updating certainly is not the proper term =).


All times are GMT -5. The time now is 02:51 PM.