Wednesday, 15 June 2011

c - How to communicate from one program to another long running program? -


I have a long lasting program in Linux under Linux:

longrun.c 100) C = 0; If (mode == 0) C ++; Other C = C + 2; Sleep (3); } Return 0; }

it will be displayed

  run @ mode 0 value: 0 runs @ mode 0 value: 1 run @ mode 0 value: 2   

I have to write some programs in C (some object like changemode.c ), so that they can communicate and set to longrun.c This value of mode for any other value, so that the running program will display values ​​in sequential order 2.

Ie, if I'm running the program after a few minutes, then it will be displayed in this pattern:

  Run @ mode 0 value: nnn run @ mode 0 value: run nnn + 2 @ mode 0 value: (nnn + 2) +2   

I can do it using the file system. Changemode.c is creating a file that is called mode = 2, then longrun.c open and check every time and go ahead is there any better way to solve it, such as interprocess communication?

If possible, can any sample changemoded write?

One of the most basic ideas in Unix programming is to flare up, and between 2 processes a pipe Installation Using the long term one, calling, and parent process, the changemode can start as a 'monitor' process, and as you are using, longrun You will now have to read / write from time to time.

A Google search will return many here.

No comments:

Post a Comment