简体   繁体   English

在Linux中在运行时重定向FIFO

[英]Redirecting FIFO in runtime in Linux

I am trying to implement a runtime reconfigurable IPC in C++ under Linux using POSIX IPC. 我正在尝试使用POSIX IPC在Linux下在C ++中实现运行时可重新配置的IPC。 In the current configuration I have a process A communicating through a FIFO with a process B. The process B takes the data from the FIFO, make some modifications and sends them to another process C through another FIFO. 在当前配置中,我有一个进程A通过FIFO与进程B进行通信。进程B从FIFO中获取数据,进行一些修改并通过另一个FIFO将它们发送到另一个进程C. Here's a graphical representation: 这是一个图形表示: 1

Then, at run-time I would like to kill the process B, and be able to allow process A to send the data through the FIFO between B and C: 然后,在运行时我想杀死进程B,并且能够允许进程A通过B和C之间的FIFO发送数据:

2

How can I do that? 我怎样才能做到这一点?

If you kill a process, its open filedescriptors are all closed. 如果您终止进程,则其打开的文件描述符全部关闭。 So if you kill B, this will cause an EOF on the FIFO as seen by C. However, if you have a named FIFO that persists after B is closed, C can continue to read from the filedescriptor associated with the FIFO, although it will return EOF immediately continuously until the other end is reopened. 因此,如果你杀死B,这将导致FIFO上的EOF,如C所示。但是,如果你有一个命名的FIFO在B关闭后仍然存在,C可以继续读取与FIFO相关的文件描述符,尽管它会立即连续返回EOF,直到另一端重新打开。

Another option is to have B send its output back to A, which then forwards that output to C. This way, it will always control what gets sent to C, and C does not have to worry about its FIFO being closed and reopened. 另一种选择是让B将其输出发送回A,然后A将该输出转发给C.这样,它将始终控制发送给C的内容,并且C不必担心其FIFO被关闭并重新打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM