85

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

Alex F
  • 42,307
  • 41
  • 144
  • 212

3 Answers3

111

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

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • Thanks, I executed "ulimit -c unlimited" from the terminal window (Ubuntu), then executed my program from the same window, and it created core dump. How can I make this mode default? When I execute my program from keyboard shortcut, dump is not created. – Alex F May 27 '10 at 08:10
  • 1
    1) `setrlimit` is a way to set the core file size from your program. 2) Or set `ulimit -c unlimited` in your profile. –  May 27 '10 at 08:28
  • 5
    Place the line in your `~/.profile`. – Philipp May 27 '10 at 08:38
  • On ubuntu 14.04 `gedit ~/.bashrc` and add `ulimit -c unlimited` to end of file and save. – mrgloom Mar 02 '16 at 09:48
55

You can do it this way inside a 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);
user2167243
  • 551
  • 4
  • 2
14

By default many profiles are defaulted to 0 core file size because the average user doesn't know what to do with them.

Try ulimit -c unlimited before running your program.

msw
  • 42,753
  • 9
  • 87
  • 112