20

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
  • 39,765
  • 26
  • 162
  • 323

4 Answers4

23

Call gdb, then

attach pid
gcore

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

Wintermute
  • 42,983
  • 5
  • 77
  • 80
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,287
  • 7
  • 55
  • 98
14

You can do it within your code with:

if (fork() == 0) abort();
Marian
  • 7,402
  • 2
  • 22
  • 34
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.
 */