输出/ proc / xx / map为/ bin / bash

时间:2014-05-13 05:05:33

标签: linux

我使用64位debian(Linux alexDesktop 2.6.32-5-amd64#1 SMP Fri 2月15日15:39:52 UTC 2013 x86_64 GNU / Linux)。

我正在尝试了解linux中的内存映射 / bin / bash是我的榜样。

ps输出:

  PID TTY          TIME CMD
23921 pts/48   00:00:00 bash
29431 pts/48   00:00:00 ps

cat /proc/23921/maps输出:

00400000-004d9000 r-xp 00000000 08:02 4350017                            /bin/bash
006d9000-006e2000 rw-p 000d9000 08:02 4350017                            /bin/bash
006e2000-006e8000 rw-p 00000000 00:00 0
00fac000-01001000 rw-p 00000000 00:00 0                                  [heap]
7f47d6a4c000-7f47d6a57000 r-xp 00000000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6a57000-7f47d6c56000 ---p 0000b000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6c56000-7f47d6c57000 r--p 0000a000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6c57000-7f47d6c58000 rw-p 0000b000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6c58000-7f47d6c62000 r-xp 00000000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6c62000-7f47d6e61000 ---p 0000a000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6e61000-7f47d6e62000 r--p 00009000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6e62000-7f47d6e63000 rw-p 0000a000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6e63000-7f47d6e78000 r-xp 00000000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d6e78000-7f47d7077000 ---p 00015000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d7077000-7f47d7078000 r--p 00014000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d7078000-7f47d7079000 rw-p 00015000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d7079000-7f47d707b000 rw-p 00000000 00:00 0
7f47d707b000-7f47d7082000 r-xp 00000000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7082000-7f47d7281000 ---p 00007000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7281000-7f47d7282000 r--p 00006000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7282000-7f47d7283000 rw-p 00007000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7283000-7f47d72a8000 r-xp 00000000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d72a8000-7f47d74a7000 ---p 00025000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d74a7000-7f47d74ab000 r--p 00024000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d74ab000-7f47d74ac000 rw-p 00028000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d74ac000-7f47d762c000 r-xp 00000000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d762c000-7f47d782c000 ---p 00180000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d782c000-7f47d7830000 r--p 00180000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d7830000-7f47d7831000 rw-p 00184000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d7831000-7f47d7836000 rw-p 00000000 00:00 0
7f47d7836000-7f47d7838000 r-xp 00000000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7838000-7f47d7a38000 ---p 00002000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7a38000-7f47d7a39000 r--p 00002000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7a39000-7f47d7a3a000 rw-p 00003000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7a3a000-7f47d7a5b000 r-xp 00000000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7a5b000-7f47d7c5a000 ---p 00021000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7c5a000-7f47d7c5b000 r--p 00020000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7c5b000-7f47d7c5c000 rw-p 00021000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7c5c000-7f47d7c7c000 r-xp 00000000 08:02 887370                     /lib/x86_64-linux-gnu/ld-2.13.so
7f47d7e6c000-7f47d7e70000 rw-p 00000000 00:00 0
7f47d7e79000-7f47d7e7b000 rw-p 00000000 00:00 0
7f47d7e7b000-7f47d7e7c000 r--p 0001f000 08:02 887370                     /lib/x86_64-linux-gnu/ld-2.13.so
7f47d7e7c000-7f47d7e7d000 rw-p 00020000 08:02 887370                     /lib/x86_64-linux-gnu/ld-2.13.so
7f47d7e7d000-7f47d7e7e000 rw-p 00000000 00:00 0
7fff4bc2a000-7fff4bc3f000 rw-p 00000000 00:00 0                          [stack]
7fff4bc41000-7fff4bc42000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

有人可以解释为什么输出的前四行与另一行不同? 地址有32位地址,而不是64位。

1 个答案:

答案 0 :(得分:3)

此输出由show_map_vma中的fs/task_mmu.c生成。相关的代码行是:

seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
                start,
                end,
                flags & VM_READ ? 'r' : '-',
                flags & VM_WRITE ? 'w' : '-',
                flags & VM_EXEC ? 'x' : '-',
                flags & VM_MAYSHARE ? 's' : 'p',
                pgoff,
                MAJOR(dev), MINOR(dev), ino);

因此,您可以看到标准printf - 样式格式指定%08lx,表示最少8个十六进制数字,前缀为零。任何大于此数字(也称为64位值)的数字都会打印更多数字。


发出命令readelf -l $(which bash)将列出其程序头。您将看到bash ELF文件已链接,以便其.text(和其他)部分在虚拟地址0x400000处加载。 /proc/[pid]/maps的输出只是反映了这一点。