我应该担心管道溢出吗?

发布于 2024-12-29 11:03:11 字数 105 浏览 1 评论 0原文

有两个进程(父进程和子进程)通过管道进行通信。父进程正在等待其子进程退出,然后从管道的读取端读取数据。孩子可能会产生相当多的输出。管道是否有可能因为其中有太多未读数据而失败并丢失一些子进程的输出?

There are two processes (parent and child) communicating through a pipe. The parent is waiting for its child to exit, then reads data from the read end of the pipe. The child may produce quite a lot of output. Is it possible for the pipe to fail because of too much unread data in it and lose some of the child's output?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆追雨的时光 2025-01-05 11:03:11

无需担心:在标准 2.6 或 3.0 内核上,管道缓冲区为 64k - 因此,如果缓冲区已满,第一个进程将在写入时阻塞。

另一方面,如果这太小,请在两个工作线程之间使用缓冲区,它具有可配置的内存大小

No need to worry about that: On a standard 2.6 or 3.0 Kernel the pipe buffer is 64k - so the first process will block on write, if the buffer runs full.

If on the other hand this is too little, use buffer between the two workers, which has a configurable memory size

逆流 2025-01-05 11:03:11

是的,如果管道填满了子进程块,就会出现死锁。

这也是 python 中遇到的问题,请参阅 [1] 第 17.1.2 节中的 Popen.wait() 警告;他们使用沟通方法来避免这个问题。

[1] http://docs.python.org/library/subprocess.html

Yes, if the pipe fills up the child process blocks and you get a deadlock.

This is a problem encountered also in python, see the Popen.wait() warning at [1], section 17.1.2; they used the communicate method to avoid the issue.

[1] http://docs.python.org/library/subprocess.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文