[英]Core dump file is not generated
Every time, my application crash a core dump file is not generated.每次,我的应用程序崩溃时都不会生成核心转储文件。 I remember that few days ago, on another server it was generated.我记得几天前,它是在另一台服务器上生成的。 I'm running the app using screen in bash like this:我正在使用 bash 中的屏幕运行应用程序,如下所示:
#!/bin/bash
ulimit -c unlimited
while true; do ./server; done
As you can see I'm using ulimit -c unlimited
which is important if I want to generate a core dump, but it still doesn't generate it, when I got an segmentation fault.如您所见,我正在使用ulimit -c unlimited
如果我想生成核心转储,这很重要,但是当我遇到分段错误时它仍然不会生成它。 How can I make it work?我怎样才能让它工作?
This link contains a good checklist why core dumps are not generated:此链接包含一个很好的清单,为什么不生成核心转储:
exit()
instead of using the core dump handler.应用程序调用了exit()
而不是使用核心转储处理程序。Make sure your current directory (at the time of crash -- server
may change directories) is writable.确保您的当前目录(在崩溃时—— server
可能会更改目录)是可写的。 If the server calls setuid
, the directory has to be writable by that user.如果服务器调用setuid
,则该目录必须可由该用户写入。
Also check /proc/sys/kernel/core_pattern
.还要检查/proc/sys/kernel/core_pattern
。 That may redirect core dumps to another directory, and that directory must be writable.这可能会将核心转储重定向到另一个目录,并且该目录必须是可写的。 More info here .更多信息在这里。
Check:查看:
$ sysctl kernel.core_pattern
to see how your dumps are created (%e will be the process name, and %t will be the system time).查看您的转储是如何创建的(%e 将是进程名称,%t 将是系统时间)。
For Ubuntu, dumps are created by apport
in /var/crash
, but in different format (see inside file).对于 Ubuntu,转储由/var/crash
中的apport
创建,但格式不同(请参阅内部文件)。
You can test it by:您可以通过以下方式对其进行测试:
sleep 10 &
killall -SIGSEGV sleep
If core dumping is successful, you will see “(core dumped)” after the segmentation fault indication.如果核心转储成功,您将在分段错误指示后看到“(核心转储)”。
Read more:阅读更多:
For systemd
systems 1 , install the package systemd-coredump
.对于systemd
系统1 ,安装软件包systemd-coredump
。 Coredumps can be found via:可以通过以下方式找到核心转储:
ls /var/lib/systemd/coredump
Furthermore, these coredumps are compressed in the lz4
format.此外,这些核心转储以lz4
格式压缩。 To decompress, you can use the package liblz4-tool
like this: lz4 -d FILE
.要解压缩,您可以像这样使用软件包liblz4-tool
: lz4 -d FILE
。 To be able to debug the decompressed coredump using gdb
, I also had to rename the utterly long filename into something shorter...为了能够使用gdb
调试解压缩的核心转储,我还必须将完全长的文件名重命名为更短的文件名......
1 Debian 9 Stretch 1 Debian 9 拉伸
Remember if you are starting the server from a service , it will start a different bash session so the ulimit won't be effective there.请记住,如果您从服务启动服务器,它将启动不同的 bash 会话,因此 ulimit 不会在那里生效。 Try to put this in your script itself :尝试将其放入您的脚本本身:
ulimit -c unlimited
Note: If you have written any crash handler yourself, then the core might not get generated.注意:如果您自己编写了任何崩溃处理程序,则可能不会生成核心。 So search for code with something on the line:所以搜索一下代码就行了:
signal(SIGSEGV, <handler> );
so the SIGSEGV will be handled by handler and you will not get the core dump.因此 SIGSEGV 将由处理程序处理,您将不会获得核心转储。
The answers given here cover pretty well most scenarios for which core dump is not created.这里给出的答案很好地涵盖了大多数未创建核心转储的场景。 However, in my instance, none of these applied.但是,在我的例子中,这些都不适用。 I'm posting this answer as an addition to the other answers.我将此答案发布为其他答案的补充。
If your core file is not being created for whatever reason, I recommend looking at the /var/log/messages.如果由于某种原因没有创建您的核心文件,我建议查看 /var/log/messages。 There might be a hint in there to why the core file is not created.那里可能会提示为什么不创建核心文件。 In my case there was a line stating the root cause:就我而言,有一行说明了根本原因:
Executable '/path/to/executable' doesn't belong to any package
To work around this issue edit /etc/abrt/abrt-action-save-package-data.conf and change ProcessUnpackaged from 'no' to 'yes'.要解决此问题,请编辑 /etc/abrt/abrt-action-save-package-data.conf 并将 ProcessUnpackaged 从“否”更改为“是”。
ProcessUnpackaged = yes
This setting specifies whether to create core for binaries not installed with package manager.此设置指定是否为未使用包管理器安装的二进制文件创建核心。
If you call daemon() and then daemonize a process, by default the current working directory will change to /
.如果您调用daemon()然后守护进程,默认情况下当前工作目录将更改为/
。 So if your program is a daemon then you should be looking for a core in /
directory and not in the directory of the binary.因此,如果您的程序是守护程序,那么您应该在/
目录中而不是在二进制目录中寻找核心。
If one is on a Linux distro (eg CentOS, Debian) then perhaps the most accessible way to find out about core files and related conditions is in the man page.如果您使用的是 Linux 发行版(例如 CentOS、Debian),那么查找核心文件和相关条件的最方便的方法可能是在手册页中。 Just run the following command from a terminal:只需从终端运行以下命令:
man 5 core
Also, check to make sure you have enough disk space on /var/core
or wherever your core dumps get written.此外,检查以确保/var/core
或写入核心转储的任何位置有足够的磁盘空间。 If the partition is almos full or at 100% disk usage then that would be the problem.如果分区几乎已满或磁盘使用率为 100%,那么这就是问题所在。 My core dumps average a few gigs so you should be sure to have at least 5-10 gig available on the partition.我的核心转储平均有几个 gig,所以您应该确保分区上至少有 5-10 gig 可用。
Although this isn't going to be a problem for the person who asked the question, because they ran the program that was to produce the core file in a script with the ulimit command, I'd like to document that the ulimit command is specific to the shell in which you run it (like environment variables).尽管对于提出问题的人来说这不会成为问题,因为他们运行的程序是使用 ulimit 命令在脚本中生成核心文件,但我想记录下 ulimit 命令是特定的到您运行它的外壳(如环境变量)。 I spent way too much time running ulimit and sysctl and stuff in one shell, and the command that I wanted to dump core in the other shell, and wondering why the core file was not produced.我花了太多时间在一个 shell 中运行 ulimit 和 sysctl 以及我想在另一个 shell 中转储核心的命令,并想知道为什么没有生成核心文件。
I will be adding it to my bashrc.我会将它添加到我的 bashrc 中。 The sysctl works for all processes once it is issued, but the ulimit only works for the shell in which it is issued (maybe also the descendents too) - but not for other shells that happen to be running. sysctl 发布后适用于所有进程,但 ulimit 仅适用于发布它的 shell(可能也适用于后代) - 但不适用于碰巧正在运行的其他 shell。
Just in case someone else stumbles on this.以防万一其他人偶然发现这一点。 I was running someone else's code - make sure they are not handling the signal, so they can gracefully exit.我正在运行其他人的代码 - 确保他们没有处理信号,以便他们可以优雅地退出。 I commented out the handling, and got the core dump.我注释掉了处理,并得到了核心转储。
In centos,if you are not root account to generate core file: you must be set the account has a root privilege or login root account:在centos中,如果你不是root账号生成core文件:你必须设置账号有root权限或者登录root账号:
vim /etc/security/limits.conf vim /etc/security/limits.conf
account soft core unlimited帐号软核无限
account hard core unlimited账户硬核无限
then if you in login shell with securecrt or other:那么如果您使用securecrt或其他方式登录shell:
logout and then relogin注销然后重新登录
Allow Dump from Daemons To allow all daemons witch are started by systemd to core dump.允许从守护进程转储 允许所有由 systemd 启动的守护进程进行核心转储。
Edit: /etc/systemd/system.conf add following编辑:/etc/systemd/system.conf 添加以下内容
DefaultLimitCORE=infinity Edit: /etc/sysctl.d/core.conf add following DefaultLimitCORE=infinity 编辑:/etc/sysctl.d/core.conf 添加以下内容
kernel.core_pattern = /var/lib/coredumps/core-%e-sig%s-user%u-group%g-pid%p-time%t kernel.core_uses_pid = 1 fs.suid_dumpable = 2 kernel.core_pattern = /var/lib/coredumps/core-%e-sig%s-user%u-group%g-pid%p-time%t kernel.core_uses_pid = 1 fs.suid_dumpable = 2
more detail: https://pve.proxmox.com/wiki/Enable_Core_Dump_systemd更多细节: https ://pve.proxmox.com/wiki/Enable_Core_Dump_systemd
Our application stopped producing core dumps when a capability was set to it.我们的应用程序在设置了功能后停止生成核心转储。
setcap 'cap_sys_nice=eip' /usr/bin/${our_app}
Removing it allowed the re-generation of coredumps.删除它允许重新生成核心转储。
setcap '-r' /usr/bin/${our_app}
See also: How do I get a coredump from a setcap executable?另请参阅: 如何从 setcap 可执行文件中获取核心转储?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.