Interprocess communication with a Daemon

funnyCoder picture funnyCoder · Jul 17, 2011 · Viewed 11.9k times · Source

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.

Answer

Max E. picture Max E. · Jul 17, 2011

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.