1

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.

  • It sounds like you may want to try using a debugger. gdb for example. – Kusalananda Sep 2 '19 at 7:08
1

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 Sep 2 '19 at 7:34
  • 2
    There's no such thing as "the whole operating system stack". Each process has its own stack mapped in its virtual memory space. – Marco Bonelli Sep 2 '19 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 Sep 2 '19 at 7:41
  • @renga_in_stack if this correctly answered your question, please accept the answer by clicking on the green mark on the top left near the vote buttons, so that this question can be marked as solved. – Marco Bonelli Sep 2 '19 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.