Ubuntu 1804 And Above Coredump Settings

查看 coredump 是否开启

bash 复制代码
# 查询, 0 未开启, unlimited 开启
xiao@Ubuntu:/var/core$ ulimit -c
0

# 开启
xiao@Ubuntu:/var/core$ ulimit -c unlimited

查看 coredump 保存路径

默认情况下,Ubuntu 使用 apport 服务处理 coredump 文件,不会将 coredump 保存到程序运行的目录下。

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E

# If the first character of the pattern is a '|', the kernel will treat
# the rest of the pattern as a command to run.  The core dump will be
# written to the standard input of that program instead of to a file.

disable ubuntu apport service through systemctl

bash 复制代码
# 关闭 ubuntu 官方错误收集服务
sudo systemctl disable apport.service
sudo systemctl stop apport.service

# 开启 ubuntu 官方错误收集服务
sudo systemctl enable apport.service
sudo systemctl start apport.service

disable ubuntu apport service through config file

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /etc/default/apport 
# set this to 0 to disable apport, or to 1 to enable it
# you can temporarily override this with
# sudo service apport start force_start=1
enabled=1

关闭 apport servie 后,查看 /proc/sys/kernel/core_pattern 文件

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /proc/sys/kernel/core_pattern 
core

使用 systemd-coredump 服务处理 coredump 文件

也可以使用 systemd-coredump 服务管理 coredump 文件,如下所示。

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /proc/sys/kernel/core_pattern
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %e

手动安装 systemc-coredump 服务

bash 复制代码
sudo apt install systemd-coredump
# Reset all sysctl settings. Default no need to run.
systemctl restart systemd-sysctl

如果使用 systemd-coredump 服务,我们可以使用 coredumpctl 命令查看 coredump 文件。默认的,coredump 文件保存于 /var/lib/systemd/coredump/ 目录下。


永久修改 coredump 文件名或保存路径

/etc/sysctl.conf 和 /etc/sysctl.d/ 目录下都可以修改配置,如果修改/etc/sysctl.conf 不生效,需要确认 /etc/sysctl.d/ 目录下有没有已定义的配置,将会覆盖 /etc/sysctl.conf中的配置.

bash 复制代码
# 需要 root 权限,确保你的 conf 配置不会被覆盖
sudo bash && echo "kernel.core_pattern=/var/core/core_%e_%p" > /etc/sysctl.d/100-coredump.conf
# load config. if no config file, /etc/sysctl.conf is default.
sudo sysctl --p /etc/sysctl.d/100-coredump.conf

临时修改 coredump 文件名或保存路径

bash 复制代码
sysctl -w kernel.core_pattern="%e-%s.core"

References

相关推荐
指尖的爷1 天前
【地狱级难度】ubuntu系统GOCV编译安装
linux·运维·ubuntu
j7~1 天前
【C++微服务项目开发脚手架】(环境篇)虚拟机 + Docker + MySQL/Redis/RabbitMQ/ES/etcd/FastDFS 全套配齐
linux·c++·ubuntu·docker·vmware·项目开发·微服务脚手架
可涵不会debug1 天前
公司外怎么连接管家婆?从 SQL Server 安装到 cpolar 固定 TCP 远程登录
linux·运维·ubuntu
云泽8081 天前
从零搭建 WSL2 + Ubuntu C/C++ 开发环境:原理、实践与底层架构解析
linux·c++·windows·ubuntu·wsl2
我本善良ab2 天前
PVE使用GRUB如何复位ubuntu的管理员密码?
ubuntu·忘记密码
ι:2 天前
NUC12 Pro 安装 Ubuntu 24.04 LTS 详细教程
linux·windows·ubuntu·nuc
虚无的纽扣2 天前
【Linux】一篇文章带你吃透进程控制:fork、wait、exit到底在做什么
linux·ubuntu
别动我齐刘海2 天前
ROS2 Jazzy + C++ 实战路线——基础学习1
c++·vscode·python·ubuntu·机器学习·自动驾驶·github
浪淘沙jkp2 天前
全程无人值守完成ubuntu22.04到xubuntu 24.04.5的升级
ubuntu
sean9082 天前
Ubuntu 26.04 终端显示冗余信息
ubuntu·终端·异常