在Ubuntu 18.04和20.04中找不到核心转储文件。

8

我在 Ubuntu 18.04 和 Ubuntu 20.04 中找不到任何核心转储文件,即使我已经更改了 core file size/proc/sys/kernel/core_pattern

smart@stable:~$ ulimit -c unlimited

smart@stable:~$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 63699
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1048576
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1048576
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

smart@stable:~$ cat /proc/sys/kernel/core_pattern 
|/usr/share/apport/apport %p %s %c %d %P %E

smart@stable:~$ sudo su
root@stable:~# echo "/var/crash/core-%e-%p-%t" > /proc/sys/kernel/core_pattern

完成这些步骤后,我运行一个程序会得到“Segmentation fault”错误,但它没有在/var/crash/生成核心转储文件,这是什么问题?

4个回答

6
我知道这个问题已经超过一年了,但我不喜欢在SO上看到这么多错误的答案。如果您想逐步了解如何正确设置转储,请阅读此帖子
对于Ubuntu 20.04的简短回答,假设您已经正确设置了所有内容, enter image description here Apport捕获的常规用户转储将写入
/var/lib/apport/coredump/

5
第一个小问题是,你的目录名似乎有拼写错误:
/var/crash/

第二个更重要的问题是,您需要在Ubuntu上设置系统范围的ulimit。

以下是帮助我找到解决方案的SO帖子

I was also struggling to get coredumps and I had the same problem with ulimit. The session specific setting suggested by Niranjan also didn't work for me.

Finally I found the solution at https://serverfault.com/questions/216656/how-to-set-systemwide-ulimit-on-ubuntu

in /etc/security/limits.conf add:

root - core unlimited
*    - core unlimited

And log out / log in.

Then

ulimit -c

on the terminal should return "unlimited" and core dumps are generated.


1

对于您自己的程序,您还需要设置:

mkdir -p ~/.config/apport
printf '[main]
unpackaged=true
' >> ~/.config/apport/settings

否则:

cat /var/log/apport.log

提示:

错误:apport(pid 503174)Sat Nov 26 21:51:47 2022:可执行文件不属于软件包,忽略

然后你就没有得到 .crash 文件了。

在 Ubuntu 22.04 上进行测试。

另请参见:https://askubuntu.com/questions/1349047/where-do-i-find-core-dump-files-and-how-do-i-view-and-analyze-the-backtrace-st/1442665#1442665


1
这个“另请参阅”太棒了,谢谢你写这个。 - rfabbri

0

Apport仍然被支持吗?它在18.04中默认被掩盖,解除掩盖后尝试启用时,我得到了以下信息: apport.service不是原生服务,重定向到systemd-sysv-install。 执行:/lib/systemd/systemd-sysv-install enable apport 无法启用单元:Unit /run/systemd/generator.late/apport.service是短暂的或已生成的。 - BobDoolittle

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