是否可以转储核心但不退出进程?
Is it possible to dump the core but not exit the process?
我希望能够生成核心转储但之后不退出进程。我不需要它来继续执行,只是不要死。这是一个 C++ Ubuntu 进程。
我相信我正在以一种非常标准的方式转储核心:我通过使用 signal() 设置信号处理程序来捕获有问题的信号,我通过 setrlimit() 设置核心大小限制,然后我提示核心使用 signal() 和 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);
}
有什么办法可以在转储核心后不让进程退出?
提前致谢!
您也可以使用 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.
我希望能够生成核心转储但之后不退出进程。我不需要它来继续执行,只是不要死。这是一个 C++ Ubuntu 进程。
我相信我正在以一种非常标准的方式转储核心:我通过使用 signal() 设置信号处理程序来捕获有问题的信号,我通过 setrlimit() 设置核心大小限制,然后我提示核心使用 signal() 和 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);
}
有什么办法可以在转储核心后不让进程退出?
提前致谢!
您也可以使用 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.