Interprocess communication with a Daemon

13,664

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.

Share:
13,664

Related videos on Youtube

funnyCoder
Author by

funnyCoder

Just learning how to code things

Updated on May 23, 2022

Comments

  • funnyCoder
    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
    funnyCoder almost 13 years
    Thanks 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.
    Max E. almost 13 years
    According 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
    funnyCoder almost 13 years
    Thanks Max, i mean httpd the main daemon, which launch the apache server with the command : httpd start or stop...
  • Max E.
    Max E. almost 13 years
    It 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
    funnyCoder almost 13 years
    Thanks 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
    wcang almost 13 years
    If 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
    Subbu over 6 years
    wcang, is it possible to publish a route to a remote host using vtysh with Quagga?