tags:

views:

87

answers:

5

Hi,

I am using C language and Linux as my programming platform.

I am developing a user-space application that runs in a background, like a daemon. And my problem is, I want another user-space application to communicate with this daemon.

I know that I have to use Interprocess Communication method but I don't know what is the correct implementation.

But using IPC in my communication implementation is my other option. Actually I just want to change the attribute of my daemon by using another application. Please see below a senario:

  1. My daemon runs in a background.
  2. Then some application will control the properties of a daemon, like sleeping delay time.

My first option is by accessing a file with the values of the properties. So that my deamon will poll that values. While the other application will change that values.

I am not sure the efficiency of my options. Please advice.

THanks.

+3  A: 

You're looking for D-Bus. Store the initial values in a file, then listen over D-Bus for requests to change it.

Ignacio Vazquez-Abrams
gconf/dconf/xfconf all do pretty much EXACTLY what they want (and the second two are dbus based)
Spudd86
+2  A: 

Unix domain sockets are a simple IPC method.

Yann Ramin
Actually, im planning to create a shared library so that any application can use these APIs to communicate with the daemon. Is it possible to use domain sockets in this kind of implementation?
sasayins
+2  A: 

If I were you, I'd forego IPC completely and instead have the daemon monitor a config file for changes. IPC is only really needed if you're going to be sending thousands of messages per second and the overhead would get intolerable.

inotify is an option for file monitoring.

Reinderien
Thanks, I will just send signal instead of using inotify.
sasayins
I agree to use a config file in this case but I totally disagree that IPC should only be used for something like thousands of messages per second.
BobbyShaftoe
+3  A: 

Updating the config file and sending a signal to cause re-read is a standard practise, cheap and easy.

belisarius
+1  A: 

I'd make the daemon listen on a pipe/fifo if it's simple enough that you only need to read a couple of bytes fed in from another program. Otherwise a local domain socket is nice to run a simple protocol over.

TheMoken