如果发生崩溃,我们使用以下函数转储堆栈以获取有关崩溃的更多信息:
static void dumpStack()
{
char buf[64];
pid_t pid = getpid();
sprintf( buf, "%d", pid );
pid_t fork_result = vfork();
int status;
if( fork_result == 0 )
execlp( "pstack", "pstack", buf, NULL );
else if( fork_result > 0 )
waitpid( fork_result, &status, 0 );
else
std::cerr << "vfork failed with err=%s" << strerror( errno ) << std::endl;
}
在上面的代码中,父母永远停留在 waitPid 上。我检查了它变成僵尸的子进程的状态:
Deepak@linuxPC:~$ ps aux | grep 21054
700048982 21054 0.0 0.0 0 0 pts/0 Z+ 03:01 0:00 [pstack] <defunct>
孩子打印的堆栈也不完整。它只打印一行并退出。
#0 0x00007f61cb48d26e in waitpid () from /lib64/libpthread.so.0
不知道为什么父母无法获得这个过程。
如果我在这里遗漏任何东西,你能帮忙吗