Linux 中进程使用的内存页

发布于 2024-12-21 06:25:51 字数 53 浏览 2 评论 0 原文

我想在运行时获取 Linux 进程中所有映射页面(分配的内存)的列表。我怎样才能做到这一点?

I want to get the list of all mapped pages (allocated memory) in a Linux Process at runtime. How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

成熟的代价 2024-12-28 06:25:51

在 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 ; try cat /proc/self/maps which will show you the memory map of the process running that cat

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

记忆で 2024-12-28 06:25:51

您可以使用 /proc/[PID]/maps 来实现此目的。

You can use /proc/[PID]/maps for this.

往事风中埋 2024-12-28 06:25:51

/proc/$your_pid/maps 并检查 /proc/$your_pid 中的其他文件,它们也可能有用

/proc/$your_pid/maps and examine other files in /proc/$your_pid they may be useful too

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文