Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable core dump in my Linux C++ program [duplicate]

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?

like image 610
Alex F Avatar asked May 27 '10 07:05

Alex F


People also ask

Where do core dumps in Linux?

By default, core dumps are sent to systemd-coredump which can be configured in /etc/systemd/coredump. conf . By default, all core dumps are stored in /var/lib/systemd/coredump (due to Storage=external ) and they are compressed with zstd (due to Compress=yes ).

What is core dumping in Linux?

A core dump is a file that gets automatically generated by the Linux kernel after a program crashes. This file contains the memory, register values, and the call stack of an application at the point of crashing.


2 Answers

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>.

like image 120
Sul Aga Avatar answered Sep 21 '22 07:09

Sul Aga


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); 
like image 43
user2167243 Avatar answered Sep 21 '22 07:09

user2167243