问题
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?
回答1:
Call gdb
, then
attach pid
gcore
where pid
is the process id of the process in question.
回答2:
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
.
回答3:
You can do it within your code with:
if (fork() == 0) abort();
回答4:
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.
*/
来源:https://stackoverflow.com/questions/27586459/how-to-create-a-core-dump-even-if-the-process-is-normally-running