我有一个程序通过Linux系统上的fork()方法从C / C ++程序创建一个守护程序,并且遇到了一些我不知道的程序行为。在我调用函数checkConfiguration()之后,它将在第二次迭代之后通过它所在的while循环失败。
以下是调用它的上下文中的代码...
while (true) {
// Read the buffer (inotify)
i = 0;
length = read( fd, buffer, BUF_LEN );
if (length<0) {
std::cerr << "ERROR\n";
exit(1);
}
out->log("inotify buffer successfully read");
checkConfiguration(parser, specs);
out->log("configuration succeeded");
...
这是函数源代码......
void checkConfiguration (CmdParser parser, std::map<int, std::string> &specs) {
// If SIGHUB received, reconfigure
out->log("Begin of checkConfiguration");
if (reconfigure) {
// New Configure Values
std::map<int, std::string> temp = parser.getArgs();
configure(temp);
// Reconfigure Specs
specs[VERBOSE] = temp[VERBOSE];
specs[LOGFILE] = temp[LOGFILE];
specs[NUMVERSIONS] = temp[NUMVERSIONS];
// Reset OutputDirector
out->resetSpecs(specs);
// Signal Completion of Reconfiguration
reconfigure = false;
}
out->log("End of checkConfiguration reached");
}
以下是我在执行此程序时看到的日志消息...
inotify buffer successfully read
begin of checkConfiguration
end of checkConfiguration reached
configuration succeeded
inotify buffer successfully read
begin of checkConfiguration
end of checkConfiguration reached
因此我们知道守护进程失败了......在完成函数和返回main()之间的某个地方?我在函数调用之后立即测试了打印到stdout,以确保我的日志记录功能没有以某种方式失败。
其他可能有用的信息
我完全不知道从哪里开始。如果我能提供更多信息,请告诉我。