Domanda

My C++ program hung and I attached it to the debugger and found this stack trace, the frame zero is never completing. What is the likely issue that has gone wrong here? I still have it in the debugger if there is more information I can gather. There are other threads too.

#0  0xffffe410 in __kernel_vsyscall ()
#1  0x0083929b in write () from /lib/libc.so.6
#2  0x007d9cd4 in _IO_new_file_write () from /lib/libc.so.6
#3  0x007d9995 in new_do_write () from /lib/libc.so.6
#4  0x007d9c7f in _IO_new_do_write () from /lib/libc.so.6
#5  0x007da56e in _IO_new_file_overflow () from /lib/libc.so.6
#6  0x007d9b6c in _IO_new_file_xsputn () from /lib/libc.so.6
#7  0x007d012f in fwrite () from /lib/libc.so.6
#8  0x009a96f6 in ?? () from /usr/lib/libstdc++.so.6
#9  0x009ac66b in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) () from /usr/lib/libstdc++.so.6
#10 0x0822aa2c in printErrorMsg (format=0x848675f "#%2i %s: %s(...) %s [%p]\n") at myAssert.cpp:66

The frame 10 source code is:

void
printErrorMsg(const char *format, ...)
{
  va_list ap;
  const int size = 4096;
  char buffer[size];

  va_start(ap, format);

  vsnprintf(buffer, size, format, ap);

  va_end(ap);

  std::clog << buffer;
  std::cout << buffer; // Code is hung here in frame 10.
}

The code is attempting to print a stack trace.

È stato utile?

Soluzione

The issue appears to be that a fork()ed child process does not have a valid cout in the case that its parent was invoked via ssh and the ssh connection that started it has exited.

Solution is to stop using cout after the summoning process exits. The clog works fine because that is going to a log file set up by the fork()ed child process.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top