与 Linux 进程进行可靠的双向通信?
实现与 Linux 进程的双向通信的可靠方法是什么?
我看到 popen 似乎不支持“r”和“w”访问同时...或者至少这就是所暗示的:
类型参数是一个指向以 null 结尾的字符串的指针,该字符串必须是“r”(用于读取)或“w”(用于写入)。
(我现在很想念Erlang)
What is the reliable way of implementing bidirectional communication to a Linux process?
I see that popen does not seem to support "r" and "w" access at the same time... or at least that's what is implied:
The type argument is a pointer to a null-terminated string which must be either 'r' for reading or 'w' for writing.
(I am so missing Erlang at the moment)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Unix 域套接字是你的朋友。
您为通信通道保留一个名称,例如
/myapp/ipc
,然后两个进程都使用 UNIX 套接字打开该地址:现在您可以使用
listen
或connect
或套接字系列中的其他内容。这需要一点工作,但却是在 Linux 上实现 IPC 的最佳方法。由于 Erlang 是一种很好的语言,用于指定通过命名管道(进程)进行通信的小型服务器(进程),因此该模型应该会让您感到舒服。
Unix domain sockets are your friend.
You reserve a name for your communications channel, such as
/myapp/ipc
, and then both processes open that address using a UNIX socket:Now you can use
listen
orconnect
or whatever else in the socket family. It's a little bit of work, but is the best way to achieve IPC on Linux.Since Erlang is just a nice language for specifying little servers (processes) that communicate over named pipes (processes), this model should feel comfortable to you.
良好的旧 TCP/IP 连接对我来说一直很有效。
Good old TCP/IP connections have always worked well for me.