Interprocess communication with a Daemon
Solution 1
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.
If you want something more advanced, you can also use DBus, which offers a more sophisticated interface, but which is more complicated to learn.
Solution 2
use tcp socket if you want to use telnet to communicate with your daemon.
Related videos on Youtube
Comments
-
funnyCoder almost 2 years
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)
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?
Thanks.
-
funnyCoder almost 13 yearsThanks for the reply, is using unix domain sockets the right way to communicate locally with a daemon? do you know how we communicate (command-line) with mysqld, httpd...?
-
Max E. almost 13 yearsAccording to Mysqld's manual page (linuxcommand.org/man_pages/mysqld1.html,) the default behavior is to create a Unix domain socket in /tmp/mysql.sock, but you can specify a different path with the --socket option. As for httpd, which httpd do you mean? There are a few of them.
-
funnyCoder almost 13 yearsThanks Max, i mean httpd the main daemon, which launch the apache server with the command : httpd start or stop...
-
Max E. almost 13 yearsIt looks like Apache does this by sending signals (en.wikipedia.org/wiki/Signal_%28computing%29) directly to the process, which works if the only thing you want to ask a process to do is exit or hang up. If you want to send more different types of commands, signals won't cut it.
-
funnyCoder almost 13 yearsThanks Max, i think that the better way in my case is to do it like mysqld with a local unix domain socket. Thanks again.
-
wcang almost 13 yearsIf that's the case, just bind the TCP socket to localhost. Otherwise, you'll need to write your own (simple) tool to communicate with your daemon. Quagga routing suite does that. You can telnet into zebra,ospfd,ospf6d using telnet. In addition to telnet, quagga routing suite provides vtysh (shell) to communicate with the routing daemons.
-
Subbu over 6 yearswcang, is it possible to publish a route to a remote host using vtysh with Quagga?