domlao
domlao

Reputation: 16029

Communication between two application in the same local machine

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.

Upvotes: 5

Views: 1132

Answers (5)

TheMoken
TheMoken

Reputation: 36

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.

Upvotes: 1

Dr. belisarius
Dr. belisarius

Reputation: 61016

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

Upvotes: 4

Reinderien
Reinderien

Reputation: 15221

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.

Upvotes: 2

Yann Ramin
Yann Ramin

Reputation: 33167

Unix domain sockets are a simple IPC method.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798566

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

Upvotes: 3

Related Questions