如何程序正常运行的时候,产生core文件

Two solutions:

Method 1. signal + fork + abort:

   pid_t ChildPid;
   int Status;
   void (*PrevSIGABT)(int);

   PrevSIGIOT = signal(SIGABT, SIG_DFL);
   ChildPid = fork();
   if (ChildPid == NULL)
      abort();
   else
      waitpid(ChildPid, &Status, NULL);

   signal(SIGABT, PrevSIGABT);

Method 2. proc + elf generator
    open /proc/$pid/mem, /proc/$pid/regs, /proc/$pid/fregs, /proc/$pid/status, /proc/$pid/map
    write to elf core file

    Method 2 is used by gdb and gcore.

你可能感兴趣的:(File,null,generator,Signal)