解决 Ubuntu 20.04 不能生成 core 文件的问题

发布于:2024-03-14
阅读时长:1分钟

解决 Ubuntu 20.04 不能生成 core 文件

背景

使用 Ubuntu 20.04 测试时发现程序崩溃但没有生成 core 文件,已检查过 ulimit -cunlimited

原因

是因为 Ubuntu 20.04(貌似 18.04 也有同样的问题) 默认开启了 apport 服务导致的。每次开机 apport 服务都会重置 /proc/sys/kernel/core_pattern 文件,这就导致生成的 core 文件被 apport 清理掉了,因此要关闭 apport。

关闭 apport

sudo systemctl stop apt-daily.timer
sudo systemctl stop apt-daily.service

sudo systemctl stop apt-daily-upgrade.timer
sudo systemctl stop apt-daily-upgrade.service

sudo systemctl disable apt-daily.service
sudo systemctl disable apt-daily.timer
sudo systemctl disable apt-daily-upgrade.timer
sudo systemctl disable apt-daily-upgrade.service

systemctl stop apport.service
systemctl disable apport.service
sed -i 's@enabled=1@enabled=0@g' /etc/default/apport 

sysctl -p

参考资料

核心转储,但核心文件不在当前目录中?
解决Ubuntu重启后,core_pattern失效问题——手动关闭apport

最后更新于:2024-03-27