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?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
For Ubuntu 14.04
Check core dump enabled:
One of the lines should be :
If not :
gedit ~/.bashrc
and addulimit -c unlimited
to end of file and save, re-run terminal.Build your application with debug information :
In Makefile
-O0 -g
Run application that create core dump (core dump file with name ‘core’ should be created near application_name file):
Run under gdb:
To check where the core dumps are generated, run:
or:
where
%e
is the process name and%t
the system time. You can change it in/etc/sysctl.conf
and reloading bysysctl -p
.If the core files are not generated (test it by:
sleep 10 &
andkillall -SIGSEGV sleep
), check the limits by:ulimit -a
.If your core file size is limited, run:
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:
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?
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
if gcore is not available on your system then
Don't use kill -SEGV as that will often invoke a signal handler making it harder to diagnose the stuck process
Ubuntu 19.04
All other answers themselves didn't help me. But the following sum up did the job
Create
~/.config/apport/settings
with the following content:(This tells apport to also write core dumps for custom apps)
check:
ulimit -c
. If it outputs 0, fix it withJust for in case restart apport:
Crash files are now written in
/var/crash/
. But you cannot use them with gdb. To use them with gdb, useFurther information:
core_pattern
. Be aware, that that file might get overwritten by the apport service on restarting.ulimit -c
value might get changed automatically while you're trying other answers of the web. Be sure to check it regularly during setting up your core dump creation.References:
Better to turn on core dump programmatically using system call
setrlimit
.example:
By default you will get a core file. Check to see that the current directory of the process is writable, or no core file will be created.