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


Question

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?

1
198
1/21/2019 1:00:40 PM

Accepted Answer

This depends on what shell you are using. If you are using bash, then the ulimit command controls several settings relating to program execution, such as whether you should dump core. If you type

ulimit -c unlimited

then that will tell bash that its programs can dump cores of any size. You can specify a size such as 52M instead of unlimited if you want, but in practice this shouldn't be necessary since the size of core files will probably never be an issue for you.

In tcsh, you'd type

limit coredumpsize unlimited
231
11/17/2008 10:22:13 PM

As explained above the real question being asked here is how to enable core dumps on a system where they are not enabled. That question is answered here.

If you've come here hoping to learn how to generate a core dump for a hung process, the answer is

gcore <pid>

if gcore is not available on your system then

kill -ABRT <pid>

Don't use kill -SEGV as that will often invoke a signal handler making it harder to diagnose the stuck process


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon