Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate core dump file in Ubuntu [duplicate]

Tags:

c

coredump

I would like to know how to generate a core dump file in Ubuntu. I am using Ubuntu 8.04.1 and gcc compiler 4.2.3. I have written a simple C program to generate a core dump. I have compiled the program as in -- gcc -g badpointer.c . When I run the program its gives segmentation fault but no core dump is generated. What additional things do i have to do to generate a core dump file ?

like image 963
user496934 Avatar asked May 27 '11 12:05

user496934


People also ask

Where is core file generated Ubuntu?

You can find these crash files by executing Console and going to 'User Diagnostic Reports' section (under 'Diagnostic and Usage Information' group) or you can locate them in ~/Library/Logs/DiagnosticReports . The actual core files are generated in /cores .

Where is my core dump Ubuntu?

In Ubuntu the core dumps are handled by Apport and can be located in /var/crash/. But it is disabled by default in stable releases.

How do I get a core dump?

You can use the gcore command in the gdb (GNU Debugger) interface to get a core image of a running process. This utility accepts the pid of the process for which you want to force the core dump. To get the list of Java processes running on the machine, you can use any of the following commands: ps -ef | grep java.

What is dump file in Ubuntu?

DESCRIPTION. The default action of certain signals is to cause a process to terminate and produce a core dump file, a disk file containing an image of the process's memory at the time of termination. This image can be used in a debugger (e.g., gdb(1)) to inspect the state of the program at the time that it terminated.


2 Answers

Linux

Activate your coredumps by the following command:

ulimit -c unlimited 

Also, check the core_pattern value by:

sysctl kernel.core_pattern 

to see where your dumps are created (%e will be the process name, and %t will be the system time).

You can change it in /etc/sysctl.conf and then reload by sysctl -p.

You can test it by:

sleep 10 & killall -SIGSEGV sleep 

If core dumping is successful, you will see “(core dumped)” after the segmentation fault indication. Otherwise double-check your ulimits again.

See also:

  • How to generate a core dump in Linux on a segmentation fault?
  • How to automatically generate a stacktrace when my program crashes

Ubuntu

If you've Ubuntu, your dumps are created by Apport in /var/crash, however it's disabled by default.

For more details, check: Where do I find the core dump in Ubuntu?


macOS/OS X

In macOS, crash dumps are automatically created by Crash Reporter in form of backtraces. You can find these crash files by executing Console and going to 'User Diagnostic Reports' section (under 'Diagnostic and Usage Information' group) or you can locate them in ~/Library/Logs/DiagnosticReports.

The actual core files are generated in /cores.

Read more: How to generate core dumps in Mac OS X?

like image 90
kenorb Avatar answered Oct 12 '22 14:10

kenorb


Check the ouput of ulimit -c, if it output 0, this is why you don't have core dumped.

Use

ulimit -c unlimited

to allow core creation (maybe replace unlimited by a real size limit to be more secure) .

like image 25
Cédric Julien Avatar answered Oct 12 '22 14:10

Cédric Julien