类似于“mkfifo”的命名管道创造,但双向
我想创建一个命名管道,就像“mkfifo”创建的管道一样,但有一点需要注意。我希望管道是双向的。也就是说,我希望进程 A 写入 fifo,进程 B 从中读取,反之亦然。由“mkfifo”创建的管道允许进程 A 读取其写入管道的数据。通常我会使用两个管道,但我试图模拟一个实际设备,因此我希望 open()、read()、write() 等的语义尽可能与实际设备相似。有人知道一种无需借助两个管道或命名套接字即可完成此操作的技术吗?
I'd like to create a named pipe, like the one created by "mkfifo", but one caveat. I want the pipe to be bidirectional. That is, I want process A to write to the fifo, and process B to read from it, and vice-versa. A pipe created by "mkfifo" allows process A to read the data its written to the pipe. Normally I'd use two pipes, but I am trying to simulate an actual device so I'd like the semantics of open(), read(), write(), etc to be as similar to the actual device as possible. Anyone know of a technique to accomplish this without resorting to two pipes or a named socket?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者 pty(“伪终端接口”)。
man pty
。Or
pty
("pseudo-terminal interface").man pty
.使用 Unix 域套接字。
哦,你说过你不想使用唯一可用的解决方案 - Unix 域套接字。
在这种情况下,您只能打开两个命名管道,或者不打开两个命名管道。当然,或者为它们编写您自己的设备驱动程序 - 无论如何,您可以为开源系统执行此操作;对于闭源系统(Windows、AIX、HP-UX)来说可能会更困难。
Use a Unix-domain socket.
Oh, you said you don't want to use the only available solution - a Unix-domain socket.
In that case, you are stuck with opening two named pipes, or doing without. Or write your own device driver for them, of course - you could do it for the open source systems, anyway; it might be harder for the closed source systems (Windows, AIX, HP-UX).