Linux-core file

definition

The core file is a record file of the memory status of the program at the time when the program is abnormally terminated or crashed by the operating system. This behavior is called Core Dump (some Chinese translated as "Core Dump").

effect

Check the cause of the program crash, find the bug, and use it for debugging.

Related operations

  1. View core file switch

    ulimit -a  # 如果 core file size 为 0 ,说明没有启用core file
    
  2. Set the size of the core file

    ulimit -c <core文件大小>
    
  3. Set the core file name

    cat /proc/sys/kernel/core_uses_pid  # 查看core文件的文件名是否添加对应程序的PID作为扩展
    # 如果为0,生成的core文件名字就是 core
    # 如果为1,生成的core文件名字就是 core.xxxx , xxxx为对应程序的PID
    echo "1" > /proc/sys/kernel/core_uses_pid  # 修改core_uses_pid的值
    
    cat /proc/sys/kernel/core_pattern  # 查看core文件保存的位置和文件名格式
    echo "/corefile/core-%e-%p-%t" > core_pattern  # 更改core文件保存的位置和文件名格式
    # 将core文件统一生成到/corefile目录下,产生的文件名为core-命令名-pid-时间戳
    
    
  4. Use the core file to debug the program

    gdb -c core  # 查看生成core文件的程序名和终止此程序的信号等信息
    # 得知生成core文件的程序之后,先运行
    gdb -c core文件名 终止程序  
    # 或者
    gdb 终止程序 core文件名  
    # 再输入
    bt
    

references

https://blog.csdn.net/weixin_42135997/article/details/80732658 Core file and use under Linux

https://www.cnblogs.com/alantu2018/p/8468879.html core dump under Linux

https://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html Linux core file introduction

Guess you like

Origin blog.csdn.net/u013617791/article/details/106361008