LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2005, 03:23 PM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
get address space of my prog during runtime?


hiho@ll

i just wanted to know if it's possible to know during runtime of my programm where the heap is located or the stack ...

i wanted to write a prog, which allocates an array (or use any variable) and the pointer variable tells me where it is located (in heap, data, bss)

i know most times it's not really necessary to control such stuff
but i just wanted to know how it works, if it works

so, how can i resolve the address space of my program? and is it possible?

thx@ll
 
Old 05-16-2005, 03:29 PM   #2
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
i'm not sure about the heap but the stack you can (with x86 arch)
Code:
/* prints the top of the top */
unsigned long get_sp(void) {
     __asm__("movl %esp, %eax");
}
void main() {
    printf("0x%x", get_sp()) ;
}
you can play around with other registers and see what you get, let me know if that helps

djgerbavor3
 
Old 05-16-2005, 04:54 PM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
sbrk(0) will return the upper heap address.
 
  


Reply



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
maximun address space for a process sarunya Linux - General 1 08-30-2005 10:56 AM
What/Where is the I/O Address Space? moadon Programming 1 05-12-2005 09:13 PM
Per-process address space in x86_64? geezjan Red Hat 1 04-07-2005 04:57 AM
accessing process address space linorg Programming 5 04-15-2004 01:13 PM
Can't write in the mapped address space zhangfaquan Linux - Software 0 01-14-2003 08:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration