我有一个进程在Linux得到一个分割错误。当它失败时,我如何告诉它生成一个核心转储?
当前回答
为了激活核心转储,请执行以下操作:
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设置!
其他回答
如上所述,这里提出的真正问题是如何在未启用核心转储的系统上启用它们。这个问题在这里得到了解答。
如果您希望了解如何为挂起进程生成核心转储,那么答案是
gcore <pid>
如果gcore在您的系统上不可用,那么
kill -ABRT <pid>
不要使用kill -SEGV,因为它经常会调用信号处理程序,使诊断卡住进程更加困难
最好使用系统调用setrlimit以编程方式打开核心转储。
例子:
#include <sys/resource.h>
bool enable_core_dump(){
struct rlimit corelim;
corelim.rlim_cur = RLIM_INFINITY;
corelim.rlim_max = RLIM_INFINITY;
return (0 == setrlimit(RLIMIT_CORE, &corelim));
}
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
为了激活核心转储,请执行以下操作:
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设置!
还有更多的事情可能会影响核心转储的生成。我遇到了这些问题:
转储目录必须是可写的。默认情况下,这是进程的当前目录,但是可以通过设置/proc/sys/kernel/core_pattern来改变。 在某些情况下,/proc/sys/fs/suid_dumpable中的内核值可能会阻止内核的生成。
还有更多的情况可能会阻止手册页中描述的生成- try man核心。