Command to Read Memory Location
Hi
I am pretty newbie to linux. I just want to know if there is any command or function that i can use to read a particular memory location in linux. Thanks |
If you had a more adequate topic (And forum), you would probably get a much better answer. I have no programming experience, so I will only give you my guessing answer.
I guess you would get a buffer overflow or something, as the kernel will protect a memory location that does not belong to your running process. |
Title edited to a more suitable one.
Now go read this post concerning good thread titling: http://www.linuxquestions.org/questi...95#post1730795 |
I tried once to figure this out by setting up data stuctures in C and then looking at pointer values. What you get back is numbers like 4G (4x10^9)--way beyond the physical memory. After a little reading on Linux memory management I could see why this happens. I could also see that a complete grasp of Linux memory management would be a career unto itself...;)
In /proc, there is a virtual file called "kcore". Scanning it gives the impression that it is memory contents, but I don't know how it relates to the physical RAM. |
Quote:
|
thanks for that info,I have found replies similar to like we canot find the data at any address location we want as O.S protecs all its user sapce and it does not allow ohter programs to read address space of other users.
Also i have one more query. In linux we will have all devices mapped as files.So if it is memory mapped I/O all these devices will be mapped to a particular address space.Is there any way i can read that memory which belongs to a particular device and use that in reading the data it contains. Thanks |
This is beyond my limited knowledge, but I think you will find it useful to learn about how things are setup in /proc. I'm not aware that memory is assigned to devices. I think more in terms of memory assigned to processes.
Returning to the original question: You should be able to see the data at the virtual memory location. e.g. in C, just print out the dereferenced value of a pointer. What you can't do easily is get the actual physical location. |
Quote:
You won't be able to write a userspace program to do this; the Linux virtual memory system will foil that attempt. |
Well you can actually do it, but what would you do with the data.
Technically, and someone correct me on this if I'm wrong, couldn't you just malloc a piece of memory, then step through it using the pointer that points to it and keep dereferencing it. Note: I can almost guarantee this will cause a crash at some point. I mean, Linux protects running programs from trying to change or access the memory of other running programs ... duh, this would be bad, something a virus would do. However, if you malloc or allocate a piece of memory (one that is not being used and that the kernel gives you), you can freely look through what might be at those memory addresses. Now, I guess this is not really what you want is it :) |
Quote:
|
Quote:
I would assume that the kernel knows the mapping between a virtual memory address and the actual location in physical RAM. Where does the kernel keep this information? |
Quote:
Your program operates in a virtual machine that includes the entire memory address space available to the machine. When your program allocates memory, appropriate entries are made in the virtual memory tables, showing what virtual addresses your program has and what the current mapping to a physical address is (this can change over the time the program executes). If you try to establish a pointer and step through RAM as was suggested above, the moment you try to step into RAM that your program has not allocated, the kernel will kill your program with a Segmentation Fault error. |
Of course this all depends on the purpose ... what purpose do you have for doing this ? i.e. What do you wanna do ?
|
This is the part where it gets interesting, please allow me to jump in. Let's say you want to do some recording. You begin recording, temp files get loaded on RAM, theoretically, once they are written, that allocation should be released from memory. However, if you record for long periods, those files that have been already written to disk are being kept loaded on the physical RAM until it gets full, how do you fix, or at least control this? Also, when another application reclaims memory during that process, the recording fails. You can search my posts if you need a more detailed explanation, I don't want to repost and get banned.
|
All times are GMT -5. The time now is 10:07 AM. |