Linux 中进程使用的内存页
我想在运行时获取 Linux 进程中所有映射页面(分配的内存)的列表。我怎样才能做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想在运行时获取 Linux 进程中所有映射页面(分配的内存)的列表。我怎样才能做到这一点?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
在 Linux 上,您可以从进程内部读取并解析
/proc/self/maps
;尝试cat /proc/self/maps
,它将显示运行该cat
的进程的内存映射。从另一个进程,对于 pid 1234 的进程的映射,您可以可以读取
/proc/1234/maps
并且还有
/proc/self/smaps
等Linux 特定的 dladdr 函数有时也很有用。
如果您担心实际位于 RAM 中的页面,请使用 mincore & msync
From inside the process, on Linux, you can read and parse
/proc/self/maps
; trycat /proc/self/maps
which will show you the memory map of the process running thatcat
From another process, for the map of the process of pid 1234, you can read
/proc/1234/maps
And there is also
/proc/self/smaps
etc.The Linux specific dladdr function is sometimes useful also.
If you are concerned by pages which are really in RAM, use mincore & msync
您可以使用
/proc/[PID]/maps
来实现此目的。You can use
/proc/[PID]/maps
for this./proc/$your_pid/maps
并检查/proc/$your_pid
中的其他文件,它们也可能有用/proc/$your_pid/maps
and examine other files in/proc/$your_pid
they may be useful too