How to create a core dump even if the process is normally running? [duplicate]

◇◆丶佛笑我妖孽 提交于 2020-01-12 03:13:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!