Boost.Process wait_for_exit(child): crash?
Boost.Process wait_for_exit(child): crash?
我使用的是 Boost.Process
的 0.5 版。可在此处找到文档。我正在使用Mac OS X Yosemite。
的问题:我正在启动编译作为子进程。我想等待该过程完成。
当我的子进程正确编译时,一切都很好。
但是当我的子进程不编译时,我的代码在调用boost::process::wait_for_exit
时似乎崩溃了。
我的用户代码如下所示:
编辑:代码已被编辑以匹配最新,更正确的版本(仍然不起作用)。
s::error_code ec{};
bp::child child = bp::execute(bpi::set_args(compilationCommand),
bpi::bind_stderr(outErrLog_),
bpi::bind_stdout(outErrLog_),
bpi::inherit_env(),
bpi::set_on_error(ec));
bool compilationSuccessful = true;
if (!ec) {
s::error_code ec2;
bp::wait_for_exit(child, ec2);
if (ec2)
compilationSuccessful = false;
}
bp::wait_for_exit
的内部实现:
template <class Process>
inline int wait_for_exit(const Process &p, boost::system::error_code &ec)
{
pid_t ret;
int status;
do
{
ret = ::waitpid(p.pid, &status, 0);
} while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
if (ret == -1) {
BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR("waitpid(2) failed");
}
else
ec.clear();
return status;
}
当我的编译命令失败时,永远不会到达::waitpid
之后的代码。显示的错误是:"子项已退出;PID: xxxx;UID:yyy;退出值:1"。
问题:
- 这是一个错误还是我滥用了
boost::process::wait_for_exit
. - 避免我得到的可移植崩溃的任何解决方法?
只是看你的代码,让我印象深刻的第一件事是,直到你调用 wait_for_exit() 之后,你才真正测试说 execute() 是否成功的 "ec" 变量。如果您使用无效的子进程调用 wait_for_exit(),那么它会崩溃是完全可以理解的。
在调用 wait_for_exit() 之前先检查"ec"。
所以问题是Boost.Test
以某种方式修改了信号堆栈。
这种信号堆栈修改与Boost.Process
有交互,至少在默认Boost.Test
配置中,代码无法可靠地测试。
我用正常的主函数和一些函数重写了测试,它完成了这项工作。
相关文章:
- 更改"child's parent's style sheet"时如何将孩子的样式表重置为 Qt 默认样式表?
- clCreateFromGLBuffer crash
- Protobuf ShortDebugString() crash
- Crash in boost::archive::text_iarchive in_archive {is} boost
- OpenCV Native Android cvtColor crash
- C++:无法将参数1从Child非模板类转换为Parent模板类
- qt get child (Callout) from QChart
- 通过调用 CreateRemoteThread 来弹出 dll:crash
- 传递 boost::filesystem::p ath 到 boost::p rocess::child 会导致 Win
- 将子类实例保存在父类型变量中并通过父变量使用 Child 函数?
- 如何确保我们从 boost::child 进程中读取所有行
- 获取stacktrace for Crash,而无需在调试器中运行该应用程序
- CMake: Hide -WShadow global compile flag for child target
- C++/Qt memcpy crash with QSharedMemory
- Qt在单击按钮时调用Child-Window
- SDL_GetRendererInfo crash
- Python Numpy 方法对应于 C++ Eigen make crash
- 如何使用 boost::p rocess::child 处理路径中的空格
- Tesseract 3.02.02 Crash JRE
- Boost.Process wait_for_exit(child): crash?