Is it possible to dump the core but not exit the process?

1.5k views Asked by At

I want to be able to generate a core dump but not exit the process afterwards. I don't need it to continue execution, just not die. This is a C++ Ubuntu process.

I believe I'm dumping the core in a pretty standard way: I catch the offending signal via setting the signal handler with signal(), I set the core size limit via setrlimit() and then I prompt the core dump with signal() and raise():

signal(SIGSEGV, OnPosixSignal);

...

void OnPosixSignal(int iSignal)
{
    struct rlimit CoreLimit;
    CoreLimit.rlim_cur = RLIM_INFINITY;
    CoreLimit.rlim_max = RLIM_INFINITY;
    setrlimit(RLIMIT_CORE, &CoreLimit);
    signal(iSignal, SIG_DFL);
    raise(iSignal);
}

Is there something I can do to not have the process exit after dumping the core?

1

There are 1 answers

0
Maxim Egorushkin On BEST ANSWER

You can also do that using gcore:

Generate a core dump of a running program with process ID pid. Produced file is equivalent to a kernel produced core file as if the process crashed (and if "ulimit -c" were used to set up an appropriate core dump limit). Unlike after a crash, after gcore the program remains running without any change.