LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command to Read Memory Location (https://www.linuxquestions.org/questions/linux-general-1/command-to-read-memory-location-612151/)

gopi_phoenix 01-08-2008 11:18 PM

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

Dinithion 01-09-2008 03:45 AM

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.

trickykid 01-09-2008 08:04 AM

Title edited to a more suitable one.

Now go read this post concerning good thread titling: http://www.linuxquestions.org/questi...95#post1730795

pixellany 01-09-2008 08:27 AM

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.

SlowCoder 01-09-2008 01:06 PM

Quote:

Originally Posted by pixellany (Post 3016656)
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.

Sigh. I thought you were Da Man! ;)

gopi_phoenix 01-10-2008 01:17 AM

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

pixellany 01-10-2008 07:07 AM

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.

jiml8 01-10-2008 10:32 AM

Quote:

Originally Posted by gopi_phoenix (Post 3017477)
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

That is what the device driver does. You should access the device and read/write its memory through the driver.

You won't be able to write a userspace program to do this; the Linux virtual memory system will foil that attempt.

H_TeXMeX_H 01-10-2008 02:55 PM

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 :)

jiml8 01-11-2008 10:27 AM

Quote:

Originally Posted by H_TeXMeX_H (Post 3018139)
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 :)

You would only get the contents of your virtual memory space by doing this, not the contents of the physical memory that is at that location.

pixellany 01-12-2008 08:43 AM

Quote:

Originally Posted by jiml8 (Post 3019102)
You would only get the contents of your virtual memory space by doing this, not the contents of the physical memory that is at that location.

This is getting in pretty deep, but....
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?

jiml8 01-13-2008 05:00 PM

Quote:

Originally Posted by pixellany (Post 3020049)
This is getting in pretty deep, but....
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?

Of course the kernel knows. It keeps the information in hash tables...in the kernel (in RAM).

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.

H_TeXMeX_H 01-14-2008 01:19 PM

Of course this all depends on the purpose ... what purpose do you have for doing this ? i.e. What do you wanna do ?

G79 01-16-2008 03:13 PM

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.