LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-20-2009, 11:17 AM   #1
Aztral
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Rep: Reputation: 0
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
 
Old 07-20-2009, 11:26 AM   #2
thewebhostingdir
LQ Newbie
 
Registered: Jul 2009
Posts: 8

Rep: Reputation: 0
Do you mean how offenly it gets updated? if this is the case then please note that it will give you real time results.
 
Old 07-20-2009, 11:31 AM   #3
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
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
 
Old 07-20-2009, 11:31 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,038

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
/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.
 
Old 07-20-2009, 11:59 AM   #5
Aztral
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
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?

Last edited by Aztral; 07-20-2009 at 12:02 PM.
 
Old 07-20-2009, 12:12 PM   #6
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
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.
 
Old 07-20-2009, 12:19 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,038

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
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.
 
Old 07-20-2009, 12:25 PM   #8
Aztral
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
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.
 
Old 07-21-2009, 12:36 AM   #9
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
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.
 
Old 07-21-2009, 11:20 AM   #10
Aztral
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Simon Bridge View Post
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.
 
Old 07-21-2009, 04:49 PM   #11
jeromeNP7
Member
 
Registered: Jun 2009
Posts: 101

Rep: Reputation: 19
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

Last edited by jeromeNP7; 09-04-2009 at 09:04 PM.
 
Old 07-21-2009, 09:06 PM   #12
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,363

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
/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."
 
Old 07-22-2009, 10:08 AM   #13
thewebhostingdir
LQ Newbie
 
Registered: Jul 2009
Posts: 8

Rep: Reputation: 0
I agree with this

Quote:
Originally Posted by Simon Bridge View Post
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 ....
 
Old 07-22-2009, 11:11 AM   #14
Aztral
LQ Newbie
 
Registered: Jul 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks jerome and sundial. It makes sense to me now. Updating certainly is not the proper term =).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Boot hang after 'proc on /proc type proc (rw)' Hagoromo Slackware 13 10-05-2007 05:03 PM
where does the /proc dir get its information so that it can update? paranoid times Linux - Software 13 03-22-2006 01:26 AM
What are the Files under /proc/scsi Prassanta Suse/Novell 1 03-17-2006 02:20 AM
how to open files in /proc mohit_garg Linux - Software 2 08-11-2005 08:20 PM
structure of /proc files dmaxj Linux - General 6 06-09-2003 06:01 PM


All times are GMT -5. The time now is 01:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration