LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 01-08-2008, 11:18 PM   #1
gopi_phoenix
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Rep: Reputation: 0
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
 
Old 01-09-2008, 03:45 AM   #2
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 13.37
Posts: 436

Rep: Reputation: 56
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.
 
Old 01-09-2008, 08:04 AM   #3
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 194Reputation: 194
Title edited to a more suitable one.

Now go read this post concerning good thread titling: http://www.linuxquestions.org/questi...95#post1730795
 
Old 01-09-2008, 08:27 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.
 
Old 01-09-2008, 01:06 PM   #5
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
Quote:
Originally Posted by pixellany View Post
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!
 
Old 01-10-2008, 01:17 AM   #6
gopi_phoenix
LQ Newbie
 
Registered: Jan 2008
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
Old 01-10-2008, 07:07 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.
 
Old 01-10-2008, 10:32 AM   #8
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Quote:
Originally Posted by gopi_phoenix View Post
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.
 
Old 01-10-2008, 02:55 PM   #9
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

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

Last edited by H_TeXMeX_H; 01-10-2008 at 02:56 PM.
 
Old 01-11-2008, 10:27 AM   #10
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Quote:
Originally Posted by H_TeXMeX_H View Post
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.
 
Old 01-12-2008, 08:43 AM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by jiml8 View Post
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?
 
Old 01-13-2008, 05:00 PM   #12
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Quote:
Originally Posted by pixellany View Post
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.
 
Old 01-14-2008, 01:19 PM   #13
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266
Of course this all depends on the purpose ... what purpose do you have for doing this ? i.e. What do you wanna do ?
 
Old 01-16-2008, 03:13 PM   #14
G79
LQ Newbie
 
Registered: Jan 2008
Posts: 9

Rep: Reputation: 0
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.
 
  


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gdb memory location breaker arunachalam Linux - Software 1 09-19-2007 11:59 AM
pointing to a memory map location in C knobby67 Programming 2 08-01-2007 06:25 PM
Variable at random location in memory? Ephracis Linux - Software 2 08-27-2006 05:49 AM
Copy a function to other memory location and execute it amit_bst Programming 11 06-28-2006 11:34 PM
Newbie:Command to read from USB MEMORY marlon2006 Linux - General 2 06-06-2006 04:48 PM


All times are GMT -5. The time now is 10:46 PM.

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