我应该如何将一个程序的输出流式传输到未定义数量的程序,以便数据不会在任何地方缓冲,并且即使没有任何内容读取流,流的来源应用程序也不会阻塞,但是如果第一个提到的程序没有输出,读取流的程序会阻塞吗?
我已经尝试用 Google 搜索了一段时间,但我所找到的只是在没有任何内容读取流时程序确实会阻塞的方法。
最佳答案
How should I stream the output from one program to an undefined number of programs in such a fashion that the data isn't buffered anywhere and that the application where the stream originates from doesn't block even if there's nothing reading the stream
如果没有某种形式的缓冲区,您的要求就不可能得到满足。
最直接的选择是将输出写入文件并让消费者读取该文件。
另一种选择是使用内存映射文件形式的环形缓冲区。由于环形缓冲区的容量通常是固定的,因此需要制定处理慢速消费者的政策。选项是:阻止生产者;终止慢速消费者;让缓慢的消费者在丢失数据时以某种方式恢复。
关于linux - 在 Linux 下将程序的输出流式传输到任意数量的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051629/