In case of crash we dump the stack to get more information about the crash using below function:
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;
}
in above code the parent stuck at waitPid forever. I checked the status of child process it became zombie:
Deepak@linuxPC:~$ ps aux | grep 21054
700048982 21054 0.0 0.0 0 0 pts/0 Z+ 03:01 0:00 [pstack] <defunct>
Also the stack printed by the child is also not complete. It just prints a single line and exits.
#0 0x00007f61cb48d26e in waitpid () from /lib64/libpthread.so.0
Not sure why parent is not able to reap the process.
Can you please help if i am missing anything here