LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-12-2004, 08:32 AM   #1
fuzzhead85
Member
 
Registered: Aug 2003
Posts: 42

Rep: Reputation: 15
c/c++ programs communicating with eachother


i need help figuring out how to have 2 programs communicate. what i have going is a program that creates structures, currently this program writes these structures into a file. then i have a second program that reads that file. that works all well and good, but the structure genereating program is just a temporary piece in the larger puzzle, eventually what is gonna happen is that structures are going to be written to that file in somewhat real time. now i cant decide if i should scan this file continuously, look for the end, and then read the last structure, which seems like a huge hasle. im sure there is a better method that i just dont know about, can anyone help?
 
Old 11-12-2004, 08:44 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Check out man ipc, man shmat, or man pipe
 
Old 11-12-2004, 08:46 AM   #3
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
You might try looking at named pipes; see the popen and pclose manpages.

Basically, a named pipe is a special file that can only be written to if another process has the file open for reading. Instead of writing to the file, the data is held in memory, and can be read by the other process (streaming).

There are other forms of IPC (interprocess communication) available; loopback network sockets tend to be the first choice thesedays, but shared memory is still around as well. Try googling these terms.
 
Old 11-12-2004, 10:55 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Quoting "rjlee":
You might try looking at named pipes; see the popen and pclose manpages.
While named pipes may be an option, popen() and pclose() are about normal unnamed pipes, not named pipes. Check "man 4 fifo" (and the man pages referenced in the "see also" section) about named pipes.
  • If it is about one process writing data to another single process, only in one direction. (i.e. process A writes to process B, and process B does not write back to process A): Use a "name pipe" (also called "filesystem pipe" or "fifo"). This is the most easy option, with the least possibilities.
  • If there's more than one process that needs to read, or if there the reading process need to "talk back", but exchanging data across a network is not needed, use "filesystem sockets", IPC message queue's or IPC shared memory. I suppose filesystem sockets are the easiest, because you don't need signalling, semaphores...
  • If you need to pass the the data over a network, use TCP (or maybe UDP) sockets. Also when you think this may be needed in the future, use these network sockets, and use the loopback interface (IP-address 127.0.0.1) when connecting to the same machine.

Last edited by Hko; 11-12-2004 at 10:56 AM.
 
Old 11-12-2004, 03:09 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
To add to what Hko wrote you have also a possibility to use local sockets (or Unix domain sockets) designed to work between programs on the same machine.
 
Old 11-13-2004, 09:08 AM   #6
fuzzhead85
Member
 
Registered: Aug 2003
Posts: 42

Original Poster
Rep: Reputation: 15
thanks for the help guys, now i really have some options to look into, just to give a lil more background info on my question, im writing telemetry software for my school's solar car, right now the car's internal telemetry system that brodcasts the information to the chase car, is under construdtion, so i have a program that is simulating the packets, by creating fake structures, currently those are written to a file, which will stay that way in the final version, for reference if we need it, but what also needs to happen is that a gui needs to read these structures and make graphs charts and what not. im gonna look into the options you guys gave me tonight hopefully, thanks for the help, and if you guys have any other suggestions, im all ears
 
Old 11-13-2004, 02:54 PM   #7
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Will it use a kind of network to communicate? If so, use sockets. When the real program is ready, you'll just need to change the type of socket and the whole code should just work.
 
Old 11-13-2004, 03:03 PM   #8
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
http://www.ecst.csuchico.edu/~beej/guide/
 
Old 11-13-2004, 04:54 PM   #9
fuzzhead85
Member
 
Registered: Aug 2003
Posts: 42

Original Poster
Rep: Reputation: 15
yah, when everything is said and done it should be using a serial modem, but the crew is tossing around the idea of 802.11, but so far it looks like we are gonna stick to the radio modem
 
Old 11-14-2004, 12:03 PM   #10
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Serial port programming is very similar to sockets (but there are specific options to be set). So will recommend them
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
lirc and firefox won't talk to eachother lukebeales Linux - Software 2 08-04-2009 06:45 PM
Files calling eachother in C LuderForChrist Programming 6 12-30-2004 10:59 AM
communicating with workgroup joy310 Linux - Networking 2 09-27-2004 04:12 AM
Mandrake 9.2 and Linksys wireless-B USB v2.8 adapter don't like eachother jc80 Linux - Wireless Networking 15 03-17-2004 04:07 PM
communicating two machines lakshman Linux - Networking 1 02-27-2003 01:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration