How to enable kernel dump in my Linux C ++ program

My program is written in C ++. compiled with gcc using the -g3 -O0 -ggdb flags. When it crashes, I want to open my main dump. Does it create a core dump file, or do I need to do something to enable the creation of a core dump, in the program itself or on the computer where it is running? Where is this file created and what is its name?

+62
c ++ linux crash-dumps
May 27 '10 at 7:59
source share
3 answers

You need to install ulimit -c . If you have 0 for this parameter, the coredump file is not created. So do this: ulimit -c unlimited and check if all ulimit -a correct. The coredump file is created when the application has completed, for example, something inappropriate. File name on my system: core.<process-pid-here> .

+80
May 27 '10 at 8:02
source share

You can do it like this inside the program:

 #include <sys/resource.h> // core dumps may be disallowed by parent of this process; change that struct rlimit core_limits; core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &core_limits); 
+39
Mar 13 '13 at 20:31
source share

By default, many profiles use 0 by default the size of the main file, because the average user does not know what to do with them.

Try ulimit -c unlimited before running your program.

+11
May 27 '10 at 8:03 a.m.
source share



All Articles