By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

data transfer

P: n/a
Hey,

I need to make two programs I wrote to communicate with each other,
but what's the best way to implement it? Both programs will be running
on the same machine.
I don't want to open sockets and transfer the data 'network style'
because of security issues.

The data transfer is only one way, program A will be sending streams
of data to program B, and program B will output the data.

I thought about using shared memory between the two applications but
how can I make program B to read from memory when program A updates
the allocated memory?

If you have a better idea I'd love to hear it :)
I'm using gcc.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
socket wrote:
Hey,

I need to make two programs I wrote to communicate with each other,
but what's the best way to implement it? Both programs will be running
on the same machine.
I don't want to open sockets and transfer the data 'network style'
because of security issues.


If the programs are on the same machine, there are no security issues. Just
yank the wire out of the wall, and your security problems are solved.

The ISO C answer is: use the file system. For a whizzier bangier answer, ask
in a newsgroup devoted to your platform; comp.unix.programmer,
comp.os.linux.development.apps, comp.os.ms-windows.programmer.win32, or
whatever.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #2

P: n/a
>I need to make two programs I wrote to communicate with each other,
but what's the best way to implement it? Both programs will be running
on the same machine.
I don't want to open sockets and transfer the data 'network style'
because of security issues.
Then you'd better state the security issues in excruciating detail,
if you're worried about communications between two programs on the
same machine being snooped on. What the heck *CAN* you trust?
If you can't trust all the people with administrative privileges
on that machine you need to find another machine.

One possible way is to pipe data from one program (outputs via
stdout) to the other (reads stdin). How you set up the plumbing
is outside the scope of C but it can be done easily in UNIX shell
syntax. (But guess how that gets implemented on many BSD UNIX
systems? A pair of sockets.) You could also have one program write
into a file and the other one reads it (this is how MS-DOS faked
pipes, and a reasonable way to get around not having real support
for pipes) (and something else can read the file also - security
problem). Another way is to compile the two programs together and
have one call the other. Guess what you can do with a debugger?
Security problem. Another possibility is shared memory, which
requires non-standard functions (such as mmap() or the shm* functions).
Shared memory can be shared by more than two programs. Security
problem.
The data transfer is only one way, program A will be sending streams
of data to program B, and program B will output the data.
This description of the data flow begs for a pipe, if your OS
supports it.
I thought about using shared memory between the two applications but
how can I make program B to read from memory when program A updates
the allocated memory?


You won't find much in C that will help you synchronize two programs
using a shared memory segment to avoid problems such as reading the
data before it's written, or busy waiting (very inefficient on a
multi-tasking system), or deadlock.

Gordon L. Burditt
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.