我有一个进程在Linux得到一个分割错误。当它失败时,我如何告诉它生成一个核心转储?
当前回答
Ubuntu 19.04
其他的答案都帮不了我。但下面的总结起到了作用
创建~ /。配置/apport/settings包含以下内容:
[main]
unpackaged=true
(这告诉apport也为自定义应用程序编写核心转储)
检查:ulimit -c。如果输出0,用
ulimit -c unlimited
只是为了以防万一重启apport:
sudo systemctl restart apport
崩溃文件现在被写入/var/ Crash /。但是不能在gdb中使用它们。要在gdb中使用它们,请使用
apport-unpack <location_of_report> <target_directory>
进一步的信息:
一些回答建议更改core_pattern。请注意,重新启动时该文件可能会被apport服务覆盖。 仅仅停止出口并不能起到作用 ulimit -c值可能会在您尝试web的其他答案时自动更改。确保在设置核心转储创建过程中定期检查它。
引用:
https://stackoverflow.com/a/47481884/6702598
其他回答
如上所述,这里提出的真正问题是如何在未启用核心转储的系统上启用它们。这个问题在这里得到了解答。
如果您希望了解如何为挂起进程生成核心转储,那么答案是
gcore <pid>
如果gcore在您的系统上不可用,那么
kill -ABRT <pid>
不要使用kill -SEGV,因为它经常会调用信号处理程序,使诊断卡住进程更加困难
这取决于您使用的shell。如果使用bash,则ulimit命令控制与程序执行相关的几个设置,例如是否应该转储core。如果你输入
ulimit -c unlimited
然后这将告诉bash,它的程序可以转储任何大小的内核。如果你愿意,你可以指定一个大小,比如52M,而不是无限,但在实践中,这不应该是必要的,因为核心文件的大小可能永远不会成为你的问题。
在tcsh中,您需要输入
limit coredumpsize unlimited
为了激活核心转储,请执行以下操作:
In /etc/profile comment the line: # ulimit -S -c 0 > /dev/null 2>&1 In /etc/security/limits.conf comment out the line: * soft core 0 execute the cmd limit coredumpsize unlimited and check it with cmd limit: # limit coredumpsize unlimited # limit cputime unlimited filesize unlimited datasize unlimited stacksize 10240 kbytes coredumpsize unlimited memoryuse unlimited vmemoryuse unlimited descriptors 1024 memorylocked 32 kbytes maxproc 528383 # to check if the corefile gets written you can kill the relating process with cmd kill -s SEGV <PID> (should not be needed, just in case no core file gets written this can be used as a check): # kill -s SEGV <PID>
一旦corefile被写入,请确保在相关文件(1./2./3.)中再次禁用coredump设置!
默认情况下,您将得到一个核心文件。检查进程的当前目录是否可写,否则不会创建核心文件。
Ubuntu 14.04
检查内核转储是否启用: ulimit - a 其中一行应该是: 核心文件大小(块,-c)不限 如果不是: 中~ /。在文件末尾添加ulimit -c unlimited并保存,重新运行终端。 使用调试信息构建应用程序: 在Makefile中-O0 -g 运行创建核心转储的应用程序(应该在application_name文件附近创建名为“core”的核心转储文件): 。/ application_name 在gdb下运行: GDB application_name core