boost :: process系统泄漏文件描述符 [英] boost::process system leaking file descriptors

查看:98
本文介绍了boost :: process系统泄漏文件描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像boost :: process :: system正在泄漏fds:

It seems like boost::process::system is leaking fds:

假设我有这个简单的代码,每3秒刷新一次iptables配置(仅作为示例):

Let's say I have this simple code to flush iptables config every 3 seconds (just an example):

#include <boost/process.hpp>
#include <thread>


int main(void)
{
  while(true)
  {
    std::this_thread::sleep_for(std::chrono::seconds(3));
    boost::process::system(boost::process::search_path("iptables"), "-F");
  }
  return 0;
}

如果我通过列出/proc/PID/fd | wc -l <​​/code>来观察打开的文件描述符的数量,则可以看到该数量每3秒增加一次.最终,当它达到1024时,该程序将中止,因为 system 调用将引发带有 what()的异常,表明打开的文件太多!

If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l, I can see that the count increases by one every 3 seconds. Eventually, when it reaches 1024, the program will abort, because the system call will throw an exception with what() stating that there are too many open files!

如何避免这种fd泄漏?我正在使用Boost 1.69.

How can I avoid this fd leakage? I'm using boost 1.69.

boost :: process :: system 替换为 boost :: process :: child 似乎无济于事, child 似乎也泄漏了fds,无论它是否分离.

Replacing boost::process::system with boost::process::child does not seem to help, the child seems to also leak fds, no matter if it gets detached or not.

使用-track-fds = yes 的Valgrind日志: https://termbin.com/d6ud

EDIT 2: Valgrind log with --track-fds=yes: https://termbin.com/d6ud

推荐答案

问题似乎是特定版本(1.69)的boost中的错误,而不是发布的代码本身中的错误.因此,升级boost/patching bug可以解决此问题.

The problem seems to be a bug in the specific version (1.69) of boost, and not in the posted code itself. So upgrading boost/patching the bug solves this problem.

错误报告可从以下位置找到: https://github.com/boostorg/process/issues/62

The bug report can be found from here: https://github.com/boostorg/process/issues/62

这篇关于boost :: process系统泄漏文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆