19

Under Linux, when a process crashes, a core dump will be created.

However, I want to create a core dump when the process doesn't crash, but looks buggy. A remote expert need the core dump to analyze.

Under Windows, we can create a dump file of a process through task manager, and after that, the process is still running.

Is it possible under Linux?

xmllmx
  • 37,882
  • 21
  • 139
  • 300

4 Answers4

23

Call gdb, then

attach pid
gcore

where pid is the process id of the process in question.

Wintermute
  • 41,179
  • 5
  • 72
  • 75
17

You can use gcore utility right from command line:

gcore [-o filename] pid

By the way, if you want to see only stack trace of the process, gstack utility will do the job.

Both utilities come with gdb.

Evgeny Kluev
  • 24,007
  • 7
  • 53
  • 94
14

You can do it within your code with:

if (fork() == 0) abort();
Marian
  • 7,077
  • 2
  • 21
  • 32
9

If you want to do this programmatically, try using google-coredumper. Their example:

#include <google/coredumper.h>
...
WriteCoreDump('core.myprogram');
/* Keep going, we generated a core file,
 * but we didn't crash.
 */