在Linux中选择性核心转储 - 我如何选择转储的部分?

12

我正在寻找一种方法来选择核心转储中包含的部分和内存区域。
我的应用程序核心转储大小约为30GB,其中大部分位于预分配的缓冲区中,在调试时我甚至不需要这些缓冲区(稍后可以将其清零)。但是,由于转储文件太大了,应用程序崩溃后开始恢复所需的时间太长。
有没有人能想到一种预先选择哪些段将在核心转储中的方法呢?
谢谢

2个回答

17
根据 core(5) 的手册页面,您可以设置写入核心文件的映射。

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.

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. The value of this file is displayed in hexadecimal. (The default value is thus displayed as 33.) Memory-mapped I/O pages such as frame buffer are never dumped, and virtual DSO pages are always dumped, regardless of the coredump_filter value.

...

This file is only provided if the kernel was built with the CONFIG_ELF_CORE configuration option.


0

我不确定是否可以设置要转储的内存部分。

来自man 5 core

磁盘文件包含进程终止时的内存镜像

作为一个选项,您可以使用setrlimitRLIMIT_CORE参数截断核心文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接