使用正在运行的进程的共享内存收集核心转储
Posted
技术标签:
【中文标题】使用正在运行的进程的共享内存收集核心转储【英文标题】:Collect core dump with shared memory of running process 【发布时间】:2016-02-18 09:55:57 【问题描述】:核心转储只收集进程空间,但不收集为进程间通信创建的共享内存。如何使核心转储也包含正在运行的进程的共享内存?
【问题讨论】:
【参考方案1】:在/proc/PID/coredump_filter
per http://man7.org/linux/man-pages/man5/core.5.html 中设置核心文件过滤器:
控制将哪些映射写入核心转储
Since kernel 2.6.23, the Linux-specific /proc/PID/coredump_filter
file can be used to control which memory segments are written to the
core dump file in the event that a core dump is performed for the
process with the corresponding process ID.
The value in the file is a bit mask of memory mapping types (see
mmap(2)). If a bit is set in the mask, then memory mappings of the
corresponding type are dumped; otherwise they are not dumped. The
bits in this file have the following meanings:
bit 0 Dump anonymous private mappings.
bit 1 Dump anonymous shared mappings.
bit 2 Dump file-backed private mappings.
bit 3 Dump file-backed shared mappings.
bit 4 (since Linux 2.6.24)
Dump ELF headers.
bit 5 (since Linux 2.6.28)
Dump private huge pages.
bit 6 (since Linux 2.6.28)
Dump shared huge pages.
bit 7 (since Linux 4.4)
Dump private DAX pages.
bit 8 (since Linux 4.4)
Dump shared DAX pages.
By default, the following bits are set: 0, 1, 4 (if the
CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS kernel configuration option is
enabled), and 5. This default can be modified at boot time using the
coredump_filter boot option.
【讨论】:
这有帮助,我使用了 sprintf(cmd, "echo 0xff > /proc/%d/coredump_filter",getpid() );系统(cmd);它奏效了。谢谢安德鲁!【参考方案2】:核心文件捕获完整的进程地址空间,包括共享内存。您可以通过在 Linux 上使用 gcore 命令生成核心文件,然后在核心文件中检查您存储在共享内存中的特定内容来检查。
【讨论】:
我试过了,共享内存无法访问。必须有一种方法可以使用共享内存启用核心转储。请帮忙 你是从root用户生成core文件的吗? 是的,我们需要在 coredump_filter 上启用一点。以上是关于使用正在运行的进程的共享内存收集核心转储的主要内容,如果未能解决你的问题,请参考以下文章