How can a C program produce a core dump of itself without terminating?

前端 未结 5 1146
悲哀的现实
悲哀的现实 2020-12-02 14:57

I want a C program to produce a core dump under certain circumstances. This is a program that runs in a production environment and isn\'t easily stopped and restarted to adj

5条回答
  •  心在旅途
    2020-12-02 15:23

    Another way might be to use the Google Coredumper library. This creates a similar result to the fork+abort technique but plays nicer with multithreaded apps (suspends all threads for a little while before forking so that they don't make a mess in the child).

    Example:

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

提交回复
热议问题