As the memory segments are part of Linux operating system, is it possible to view their respective addresses using simple C program or any linux commands.
1 Answer
If you wrote a program and you want to see its memory mapping when it's running, you can run it in a debugger like gdb, then start it, and take a look at the memory map with the command info proc mappings, the output will be something like this:
(gdb) info proc mappings
process 6520
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x10000 0x15000 0x5000 0x0 /bin/true
0x24000 0x25000 0x1000 0x4000 /bin/true
0x25000 0x26000 0x1000 0x5000 /bin/true
0x76e6e000 0x76f98000 0x12a000 0x0 /lib/arm-linux-gnueabihf/libc-2.24.so
... etc ...
0x7efdf000 0x7f000000 0x21000 0x0 [stack]
0xffff0000 0xffff1000 0x1000 0x0 [vectors]
If you instead want to see the mappings of an already running process you can, assuming that you have the right permissions, do cat /proc/<pid>/maps. In alternative you could attach to the process with gdb -p <pid> and do what I explained above.
-
0x7efdf000 0x7f000000 0x21000 0x0 [stack]. Small query here. Does this address range refers only the particular process or the whole operating system's stack.renga_in_stack– renga_in_stack2019-09-02 07:34:01 +00:00Commented Sep 2, 2019 at 7:34
-
2There's no such thing as "the whole operating system stack". Each process has its own stack mapped in its virtual memory space.Marco Bonelli– Marco Bonelli2019-09-02 07:34:54 +00:00Commented Sep 2, 2019 at 7:34
-
Ok got ur point. I was not aware of virtual memory concepts. So i got confused little bit earlier.renga_in_stack– renga_in_stack2019-09-02 07:41:03 +00:00Commented Sep 2, 2019 at 7:41
gdbfor example.