honda4life
Posts: 75
Joined: Thu Mar 15, 2012 7:27 pm

Sending data between seperate programs

Wed Jul 24, 2013 6:16 pm

Hello,

I'm planning to using a 128x64 LCD display, I want to show some data from other programs.
I was thinking to run this task in the background with some different screens.
For example:
Screen 1:
CPU load, memory usage, disk usage, network usage.
Since this is general information, this is polled py the "lcd program" itself.

... After a while ...

Screen2:
Information from program A

... and so on, multiple programs ...

This cycles between the screens with the most recent data sent, some programs run every 5 minutes for example.

Now the question, how to feed the data in the program?
I've searched some information about named pipes, but most information is for daemons and couldn't find a good example for my purpose.
Is this the best way or other suggestions? I want to keep it as simple as possible for the clients to put data in (something like value1;10)

User avatar
joan
Posts: 15284
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Sending data between seperate programs

Wed Jul 24, 2013 7:47 pm

You could use shared memory, pipes, sockets, or files. What's best (if there is a best) would depend on the details of what you are trying to achieve and how it's expected to grow. I'd probably start with pipes.

jimmy
Posts: 12
Joined: Fri Dec 30, 2011 6:39 pm

Re: Sending data between seperate programs

Fri Aug 02, 2013 4:43 pm

A named pipe is probably the easiest way to do inter process communication, although, it does have its drawbacks. Use the Unix/Linux command to create a FIFO file, mkfifo <filename> or as an example mkfifo /tmp/myfifo. After that you can write to /tmp/myfifo (if that's the name used when you created the fifo) from one process, then read from /tmp/myfifo from the other process.

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: Sending data between seperate programs

Sun Sep 08, 2013 6:04 pm

Simply create a file in /dev/shm and mmap() it into all your processes, you will be responsible for locking and arbitrating access to the file ;)

Return to “C/C++”