了解 Linux/proc/pid/maps 或/proc/self/maps [英] Understanding Linux /proc/pid/maps or /proc/self/maps

查看:126
本文介绍了了解 Linux/proc/pid/maps 或/proc/self/maps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解我的嵌入式 Linux 应用程序的内存使用情况./proc/pid/maps 实用程序/文件似乎是查看详细信息的好资源.不幸的是,我不明白所有的列和条目.

I am trying to understand my embedded Linux application's memory use. The /proc/pid/maps utility/file seems to be a good resource for seeing the details. Unfortunately I don't understand all the columns and entries.

匿名 inode 0 条目是什么意思?这些似乎是一些较大的内存段.

What does the anonymous inode 0 entries mean? These seem to be some of the larger memory segments.

推荐答案

/proc/$PID/maps 中的每一行描述了进程或线程中的一个连续虚拟内存区域.每行都有以下字段:

Each row in /proc/$PID/maps describes a region of contiguous virtual memory in a process or thread. Each row has the following fields:

address           perms offset  dev   inode   pathname
08048000-08056000 r-xp 00000000 03:0c 64593   /usr/sbin/gpm

  • address - 这是进程地址空间中区域的起始地址和结束地址
  • 权限 - 这描述了如何访问该区域中的页面.有四种不同的权限:读取、写入、执行和共享.如果读/写/执行被禁用,将出现 - 而不是 r/w/x.如果一个区域不是共享,它是私有,所以会出现一个 p 而不是 s.如果进程尝试以不允许的方式访问内存,则会生成分段错误.可以使用 mprotect 系统调用更改权限.
  • offset - 如果区域是从文件映射的(使用 mmap),这是映射开始的文件中的偏移量.如果内存不是从文件映射的,则它只是 0.
  • 设备 - 如果区域是从文件映射的,则这是文件所在的主要和次要设备号(十六进制).
  • inode - 如果区域是从文件映射的,则这是文件编号.
  • pathname - 如果区域是从文件映射的,则这是文件的名称.对于匿名映射区域,此字段为空.还有一些特殊区域的名称,如 [heap][stack][vdso].[vdso] 代表虚拟动态共享对象.系统调用使用它来切换到内核模式.这是一篇好文章关于它:什么是 linux-gate.so.1?"
    • address - This is the starting and ending address of the region in the process's address space
    • permissions - This describes how pages in the region can be accessed. There are four different permissions: read, write, execute, and shared. If read/write/execute are disabled, a - will appear instead of the r/w/x. If a region is not shared, it is private, so a p will appear instead of an s. If the process attempts to access memory in a way that is not permitted, a segmentation fault is generated. Permissions can be changed using the mprotect system call.
    • offset - If the region was mapped from a file (using mmap), this is the offset in the file where the mapping begins. If the memory was not mapped from a file, it's just 0.
    • device - If the region was mapped from a file, this is the major and minor device number (in hex) where the file lives.
    • inode - If the region was mapped from a file, this is the file number.
    • pathname - If the region was mapped from a file, this is the name of the file. This field is blank for anonymous mapped regions. There are also special regions with names like [heap], [stack], or [vdso]. [vdso] stands for virtual dynamic shared object. It's used by system calls to switch to kernel mode. Here's a good article about it: "What is linux-gate.so.1?"
    • 您可能会注意到许多匿名区域.这些通常由 mmap 创建,但不附加到任何文件.它们用于许多杂项,例如共享内存或未在堆上分配的缓冲区.例如,我认为 pthread 库使用匿名映射区域作为新线程的堆栈.

      You might notice a lot of anonymous regions. These are usually created by mmap but are not attached to any file. They are used for a lot of miscellaneous things like shared memory or buffers not allocated on the heap. For instance, I think the pthread library uses anonymous mapped regions as stacks for new threads.

      这篇关于了解 Linux/proc/pid/maps 或/proc/self/maps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆