一个守护进程间通信 [英] Interprocess communication with a Daemon
问题描述
我想实现一个Unix守护进程(我们称之为的 myUnixd 的),并希望用户能够与通过命令行此守护程序交互,例如:
I want to implement a Unix daemon (let's call it myUnixd), and want the user to be able to interact with this daemon via the command line, for example:
myUnixd --help # will display help information
myUnixd --show # will show some data (the's deamon should be doing the work)
所以我的问题是:如何与后台程序沟通?我在想的Unix域套接字。谁能告诉我做这件事的正确方法?
So my question is: How can I communicate with the daemon? I was thinking about Unix domain sockets. Can someone tell me the right way to do this?
感谢。
推荐答案
使用 Berkeley套接字的。具体来说,您可以创建一个UNIX域套接字(也称为本地域套接字,这将创造什么看起来像一个文本文件中。写入文本文件文本发送到后台程序,从中读取接收文本从守护程序,你可以有几个函数调用实现这一点。
Use Berkeley sockets. Specifically, you can create a "UNIX domain socket" (otherwise known as a "local domain socket," which will create what looks like a text file. Write to the text file to send text to the daemon, read from it to receive text from the daemon. You can implement this with a few function calls.
如果你想要的东西更先进的,你也可以使用的DBus ,它提供了一个更复杂的界面,但它是更复杂的学习。
If you want something more advanced, you can also use DBus, which offers a more sophisticated interface, but which is more complicated to learn.
这篇关于一个守护进程间通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!