How to generate a core dump in Linux on a segmentation fault?

前端 未结 12 1275
余生分开走
余生分开走 2020-11-22 17:06

I have a process in Linux that\'s getting a segmentation fault. How can I tell it to generate a core dump when it fails?

12条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 17:40

    To check where the core dumps are generated, run:

    sysctl kernel.core_pattern
    

    or:

    cat /proc/sys/kernel/core_pattern
    

    where %e is the process name and %t the system time. You can change it in /etc/sysctl.conf and reloading by sysctl -p.

    If the core files are not generated (test it by: sleep 10 & and killall -SIGSEGV sleep), check the limits by: ulimit -a.

    If your core file size is limited, run:

    ulimit -c unlimited
    

    to make it unlimited.

    Then test again, if the core dumping is successful, you will see “(core dumped)” after the segmentation fault indication as below:

    Segmentation fault: 11 (core dumped)

    See also: core dumped - but core file is not in current directory?


    Ubuntu

    In Ubuntu the core dumps are handled by Apport and can be located in /var/crash/. However, it is disabled by default in stable releases.

    For more details, please check: Where do I find the core dump in Ubuntu?.

    macOS

    For macOS, see: How to generate core dumps in Mac OS X?

提交回复
热议问题