Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-15-2006, 05:52 PM
|
#1
|
Member
Registered: Jan 2005
Distribution: Fedora Core 3, 4
Posts: 135
Rep:
|
where does the /proc dir get its information so that it can update?
I am looking for how the files in the /proc dir get their information. Things like disk and network I/O, cpu load, and other information. How is that updated? I'm trying to write a script or program to pick up all the information for me, and since the /proc file can vary I want to get information from wherever it gets its information from.
If anyone knows where some documentation on it is, or can point me in the right direction it would be greatly appreciated.
Thanks,
Michael
|
|
|
03-15-2006, 06:26 PM
|
#2
|
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873
|
The /proc directory gets its information from the kernel data structures. The files in there are a live view of those items in the kernel. Several command line utilities get their information from the same kernel data structures. That is why looking at files in the /proc directory can be just like running one of these utilities. Some of these utilities include vmstat, iostat, and lsmod. I'm not saying that these utiltiies read their information from the /proc directory. I'm just saying that much of the same information displayed by these utilities is also available in the /proc directory.
|
|
|
03-16-2006, 01:09 AM
|
#3
|
Senior Member
Registered: Jun 2004
Posts: 2,553
Rep:
|
Quote:
I'm not saying that these utiltiies read their information from the /proc directory
|
they do read their information from the /proc directory
a little snipit of code from lsmod
Code:
file = fopen("/proc/modules", "r");
/proc is there to provide userland access to things that are generally unavailable to userspace. but there are no doubt some userspace syscalls that return some of the data represented in the /proc filesystem. Beyond that you would have to be in kernel space to have access to the data.
/proc is not just for reading . you can actually alter the kernel data structures by writing to the /proc filesystem as well.
Last edited by foo_bar_foo; 03-16-2006 at 01:31 AM.
|
|
|
03-16-2006, 01:15 AM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
If I correctly remember (and understand) what I have read, /proc does not refer to any actual files on disk---rather it is a "hook" to allow you to see what the kernel has stashed in RAM. Consistent with the Unix mantra that "everything is a file", you access the data as if it were a file. Actually, it is in RAM.
|
|
|
03-16-2006, 02:36 AM
|
#5
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
You're right pixellany. /proc is a "pseudo-filesystem". They're not real files, just representations of what your kernel has stored in memory. See also stress_junkie's post.
|
|
|
03-16-2006, 02:34 PM
|
#6
|
Member
Registered: Jan 2005
Distribution: Fedora Core 3, 4
Posts: 135
Original Poster
Rep:
|
alright, this is all really cool information, thank you everyone who has posted. A few questions, if I were to write a script to collect data from the /proc dir and display everything that I wanted in a format that I like (so that I wouldn't be using lspci, uptime, ect. to find the information that I want) would that be portable across all linux platforms, or do some distros set their /proc dir up differently then others. And I was kind of wondering how the linux kernel wrote the information to the /proc dir, so that I could understand more about it in AIX, as I've found the /proc in there is very different, and maybe knowing more in depth details about the Linux /proc would help me figure it out for other Unix systems. Thanks again for all the input.
|
|
|
03-16-2006, 02:38 PM
|
#7
|
Member
Registered: Jan 2005
Distribution: Fedora Core 3, 4
Posts: 135
Original Poster
Rep:
|
alright, this is all really cool information, thank you everyone who has posted. A few questions, if I were to write a script to collect data from the /proc dir and display everything that I wanted in a format that I like (so that I wouldn't be using lspci, uptime, ect. to find the information that I want) would that be portable across all linux platforms, or do some distros set their /proc dir up differently then others. And I was kind of wondering how the linux kernel wrote the information to the /proc dir, so that I could understand more about it in AIX, as I've found the /proc in there is very different, and maybe knowing more in depth details about the Linux /proc would help me figure it out for other Unix systems.
Quote:
The /proc directory gets its information from the kernel data structures.
|
How do kernel data structures work? I get the feeling that the answer to that question isn't a short one, if it isn't and you don't want to explain it is there some good documentation that you could recommend?
Thanks again for all the input.
|
|
|
03-16-2006, 03:28 PM
|
#8
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Are you asking what is a data structure? It is just a definition of how a data set is stored. Simple example: I'm going to transmit (store) a 32-bit segment (four bytes). Byte 1 is an ascii character, and bytes 2-4 are 3 8-bit integers whose value is derived from three voltages that I measured.
Real-world data structures are vastly more complex and may contain a mix of integer, floating-point, ascii, and single-bit flags.
Simpler answer?? Data structures are the means by which the kernel knows where it put a piece of data so it can find it again.
|
|
|
03-16-2006, 03:35 PM
|
#9
|
Member
Registered: Apr 2003
Distribution: Gentoo
Posts: 52
Rep:
|
Quote:
Originally Posted by paranoid times
A few questions, if I were to write a script to collect data from the /proc dir and display everything that I wanted in a format that I like (so that I wouldn't be using lspci, uptime, ect. to find the information that I want) would that be portable across all linux platforms, or do some distros set their /proc dir up differently then others.
|
The information provided in /proc does change between kernel versions, and may also change depending on which drivers you have loaded and/or compiled into your kernel. For example, if your system uses only SCSI or SATA and you therefore don't have IDE drivers loaded, /proc/ide shouldn't exist. For your script to work across different distributions (and indeed, different versions and installations of the same distribution), it should be prepared to fail gracefully if some piece of information is missing.
Quote:
Originally Posted by paranoid times
And I was kind of wondering how the linux kernel wrote the information to the /proc dir, so that I could understand more about it in AIX, as I've found the /proc in there is very different, and maybe knowing more in depth details about the Linux /proc would help me figure it out for other Unix systems.
|
The information is never 'written' to the /proc dir. Actually, whenever you read some data from the filesystem, the request goes to the kernel, and it is the kernel that reads the data from the appropriate place, then returns it to userspace. In the case of /proc, instead of reading the data from disk the proc fs driver looks up the appropriate information in the kernel, and returns it as if it were a real file.
I can explain the way filesystems work in Linux in more detail if you want, but the above should give you an adequate understanding of what's going on here. I don't know the specifics of /proc in AIX or other Unices, but I imagine the above is true of them too and that only the contents of the directory are different.
Quote:
Originally Posted by paranoid times
How do kernel data structures work? I get the feeling that the answer to that question isn't a short one, if it isn't and you don't want to explain it is there some good documentation that you could recommend?
|
Are you a C programmer to at least an intermediate level? It would be hard to imagine any answer to your question being very useful unless the answer to mine is 'yes' .
|
|
|
03-16-2006, 05:15 PM
|
#10
|
Member
Registered: Jan 2005
Distribution: Fedora Core 3, 4
Posts: 135
Original Poster
Rep:
|
Quote:
The information is never 'written' to the /proc dir. Actually, whenever you read some data from the filesystem, the request goes to the kernel, and it is the kernel that reads the data from the appropriate place, then returns it to userspace.
|
That answers my question, thank you, I thought all the files in /proc were getting their information from some other step and weren't in real time basically. I guess I still have a question as to what goes into the files in /proc getting their information, to try to work around it, but it doesn't look like that would work too well and I'm better off with using awk on what is already in /proc
Quote:
Are you a C programmer to at least an intermediate level? It would be hard to imagine any answer to your question being very useful unless the answer to mine is 'yes'
|
pixellany's definition kind of reminded me of what data structures are in C code, though that is the part in C that I started getting really confused so I don't really know much about structures in C if that is why you were asking if I'm a C programmer (and the answer is "no" I'm not at least an intermediate level C programmer).
Thanks to everyone, all the responses have showed me some of the holes in my attack plan, and I now have a much better idea of how the /proc dir works and what I can do with it.
|
|
|
03-16-2006, 09:45 PM
|
#11
|
Senior Member
Registered: Jun 2004
Posts: 2,553
Rep:
|
if you wish to understand the /proc filesystem as its used from within kernel space
./include/linux/proc_fs.h is the interface
and there is documentation in
./Documentation/DocBook/procfs_example.c
./Documentation/DocBook/procfs-guide
and like that
|
|
|
03-16-2006, 11:23 PM
|
#12
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by paranoid times
TI guess I still have a question as to what goes into the files in /proc getting their information, to try to work around it, but it doesn't look like that would work too well and I'm better off with using awk on what is already in /proc
|
They aren't files--they are only virtual files. The data is stored in RAM by the kernel as it executes various processes. To understand in more detail you would have to take apart what the kernel is doing when it runs a particular process.
A few days with the kernel source code will give you some clues---hopefully without causing irreversible brain damage in the bargain....
|
|
|
03-21-2006, 11:53 PM
|
#13
|
Member
Registered: Apr 2003
Distribution: Gentoo
Posts: 52
Rep:
|
Quote:
Originally Posted by paranoid times
I still have a question as to what goes into the files in /proc getting their information, to try to work around it, but it doesn't look like that would work too well and I'm better off with using awk on what is already in /proc
|
For many things in /proc, /proc is the only interface the kernel provides to get hold of that information, so you'll have to use it for those . For the other stuff I can't imagine any reason why it'd be worth the extra trouble.
|
|
|
03-22-2006, 01:26 AM
|
#14
|
Member
Registered: Jan 2005
Distribution: Fedora Core 3, 4
Posts: 135
Original Poster
Rep:
|
I don't know if I was reading it correctly but it looked to me like the procfs-guide was describing how to make your own /proc calls. It was mostly way over my head, but interesting.
It looks like the best way is just to fish things out of the /proc, then if I hit any problems with different kernels or anything just to modify the script. I think I'll work with that for now.
Thanks to everyone for all your help.
-Michael
|
|
|
All times are GMT -5. The time now is 02:45 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|