gpt4 book ai didi

c++ - std::ofstream 构造函数阻塞

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:56:13 25 4
gpt4 key购买 nike

我有以下代码:

std::ofstream stat("/opt/lic_status");
if ( stat.is_open() )
{
stat << ver;
stat.close();
}

我的问题是在第一行执行被阻止。在此 block 期间,看门狗生成了核心转储,如下所示:

(gdb) bt
#0 0x00cb5430 in __kernel_vsyscall ()
#1 0x00b2833b in open () from /lib/libc.so.6
#2 0x00ac37c8 in _IO_new_file_fopen () from /lib/libc.so.6
#3 0x00ab73dd in __fopen_internal () from /lib/libc.so.6
#4 0x00ab9c4c in fopen64 () from /lib/libc.so.6
#5 0x00d6e877 in std::__basic_file<char>::open(char const*, std::_Ios_Openmode, int) () from /usr/lib/libstdc++.so.6
#6 0x00d1d75e in std::basic_filebuf<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode) () from /usr/lib/libstdc++.so.6
#7 0x08b625b8 in open () at /usr/lib/gcc/i686-redhat-linux/4.4.4/../../../../include /c++/4.4.4/fstream:699
#8 basic_ofstream () at /usr/lib/gcc/i686-redhat-linux/4.4.4/../../../../include/c++/4.4.4/fstream:628

需要说明的是,我不知道问题发生时/opt/lic_status 文件的状态是什么。我不知道它是否被其他进程打开,甚至根本不存在。

有人对造成这种情况的原因有什么建议吗?我只有 coredump,我可以从中获取任何信息吗?

最佳答案

"I need to mention that I don't know what was the state of the /opt/lic_status file when the problem occurred. I don't know if it was opened by other process or even if it existed at all."

根据我的理解,文件的上述属性/状态都不会导致程序在该特定行上阻塞(即用户模式程序在 中调用 open() >std::ofstream 构造函数)。每当用户模式程序调用open() 系统调用打开文件时,系统将完成调用并返回适当的错误代码。系统(内核模式)不会返回到用户模式的情况不会发生。

Does anyone have any suggestion on what could have caused this? I only have the coredump, can I get any info out of it?

  1. 整个系统(内核)状态不佳(由于某些未知原因)。
  2. 该程序是多线程的,一些其他线程已卡在某处。通过查看此线程的调用堆栈,它看起来正常,因为它正在内核模式下执行并调用 open() 系统调用。

如果我们遇到第一种情况,那么我相信我们不能做太多,程序的核心转储文件不会提供任何额外信息来识别/确认这一点。核心转储文件仅包含该特定进程的快照。

但是,如果我们是第二种情况,那么我们应该尝试进一步分析核心转储文件。加载核心转储文件后,我们可以在 GDB 命令提示符下执行以下命令。

$info threads
$thread apply all backtrace

上述命令将提供信息(如果您的程序是多线程的)以及所有线程的调用堆栈。这可能有助于理解您的问题。如果您已经完成上述信息,则可以忽略。

关于c++ - std::ofstream 构造函数阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25806976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com