Linux 更改核心转储的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16048101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:44:00  来源:igfitidea点击:

Changing location of core dump

linuxcrash-dumpscoredumprecovery

提问by rogue_knight9

I want to change the default location of core dump files so that every time a core dump is generated ,it goes to that directory.Also, is it possible to save the dump file by the name of the crashed file in this location?

我想更改核心转储文件的默认位置,以便每次生成核心转储时,它都会转到该目录。另外,是否可以在此位置按崩溃文件的名称保存转储文件?

采纳答案by mata

Yes, it is. You can change /proc/sys/kernel/core_patternto define the pathname used to generate the corefile. For more, see man core

是的。您可以更改/proc/sys/kernel/core_pattern以定义用于生成核心文件的路径名。有关更多信息,请参阅man core

example:

例子:

echo '/tmp/core_%e.%p' | sudo tee /proc/sys/kernel/core_pattern    # `tee' instead of > so that
                                                                   # opening happens in the
                                                                   # elevated process

would cause all future core dumps to be generated in /tmpand be named core_[program].[pid]

将导致所有未来的核心转储生成/tmp并命名core_[program].[pid]

回答by Michael Potter

Before following the instructions in the accepted answer, it could be good idea to check the contents of /proc/sys/kernel/core_patternto see if the Redhat abrt system is in use.

在按照已接受的答案中的说明进行操作之前,最好先检查 的内容/proc/sys/kernel/core_pattern以查看 Redhat abrt 系统是否正在使用中。

-> cat /proc/sys/kernel/core_pattern
|/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t e

If that is in use, then you already have a pretty extensive scheme for managing core files that you would want to understand before you override it.

如果正在使用它,那么您已经有一个非常广泛的管理核心文件的方案,您希望在覆盖它之前了解它。

In a nutshell, abrt:

简而言之,abrt:

  1. puts the core files here: /var/spool/abrt/
  2. has a gui that is started with the command abrt-gui
  3. augments the corefile with additional information about the failed process.
  4. is configure with this file: /etc/abrt/abrt-action-save-package-data.conf
  1. 将核心文件放在这里: /var/spool/abrt/
  2. 有一个以命令开头的 gui abrt-gui
  3. 使用有关失败进程的附加信息来扩充核心文件。
  4. 是用这个文件配置的: /etc/abrt/abrt-action-save-package-data.conf

One common stumbling block with using it is to change this line in the config file:

使用它的一个常见障碍是更改配置文件中的这一行:

ProcessUnpackaged = no

Change that to yes to capture core files from your homebrew processes, otherwise it will only capture corefiles from programs installed by the package manager.

将其更改为 yes 以从您的自制进程捕获核心文件,否则它只会从包管理器安装的程序中捕获核心文件。

[EDIT to answer how to use coredump] To examine a core dump I do this:

[编辑回答如何使用 coredump] 要检查核心转储,我这样做:

cd /var/spool/abrt/XXXXXXX
gdb $(cat executable) coredump

There might be a better way to so that, but gdb has served me well so I have not looked for other ways. Just replace XXXXXXX with the folder that contains your coredump file. The gdb command is cut and paste ready.

可能有更好的方法来做到这一点,但是 gdb 已经很好地为我服务,所以我没有寻找其他方法。只需将 XXXXXXX 替换为包含您的 coredump 文件的文件夹。gdb 命令已准备好剪切和粘贴。

References:

参考:

Redhat Book

红帽书

CentOS Forum

CentOS 论坛