|
 |
|
 |
04-30-2006, 12:50 AM
|
#1 (permalink)
|
|
Jade Phoenix
Join Date: Apr 2006
Location: Ontario, Canada
Posts: 38
|
Inter-Process Communication (IPC) in C++
Hey all,
This is my first post, so "Hello World!" and hopefully I'll be chatting and discussing things with you all more now that I'm registered.
Anyways, I will soon be starting a project (that will run on UNIX) where I'll have 2 processes working together. Basically, the one process will interact with the user and in another window the 2nd process will display the results of the interaction in various ways.
What I want if for process 1 to send little messages to process 2 so that p2 can update the results display. I've thought about pipes and shared memory, but was wondering if any of you could give some advice on what to do about this. I don't really need any super fancy features but I want to be able to communicate an object or message with a few variables inside of it, not just a stream of text like I've seen in some examples. Is this possible?
Thanks in advance,
dazz.
[edited for spelling]
Last edited by dazz williams; 04-30-2006 at 12:59 PM.
|
|
|
04-30-2006, 01:01 PM
|
#2 (permalink)
|
|
Anti-Zealot
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 72
|
Yes, its completely possible.
You'll want to look into IPC. I wrote something similar for a proxy server and web server using SysV Shared Memory and Semaphores. There's a POSIX version, but the man pages for it say it doesn't work for separate processes, only within the same process in just about every Operating System. However, every OS that I've run the POSIX versions on work between processes, despite the man page saying otherwise.
Though, you can do this in a couple ways.
You can skip IPC completely and use sockets to communicate between processes. This will work well and allow you to have the processes network transparently in the future. The performance won't be as good as with Shared Memory, but it will work fast enough for what you're after (Shared Memory starts to spank using sockets as transfers get larger). If you're simply sending messages, the best way is to use sockets (you may actually get better performance this way, even).
If you decide you want to delve into IPC, "man ipc". I, or someone else, can give you more help if you get stuck (for sockets as well, of course), its really easy once you understand what you have to do (you'll need two shared semaphores and some amount of shared memory to do what you want). IPC has a few ways that things can be done, as well.
I'd strongly suggest using sockets, in this case. Whatever you decide, just post again and we can help you out some more.
__________________
If you always think like an expert, you'll always be a beginner. | "A handful of knowledgeable people is more effective than an army of fools" -Writing Secure Code, 2nd Ed.
|
|
|
05-02-2006, 09:56 AM
|
#3 (permalink)
|
|
Jade Phoenix
Join Date: Apr 2006
Location: Ontario, Canada
Posts: 38
|
IPC and sockets, thanks
AssKoala,
Thanks for the heads up. I'll start fooling around with things and I'll post again later/another day with my successes and/or failures.
Thanks,
dazz.
|
|
|
05-05-2006, 09:59 PM
|
#4 (permalink)
|
|
Jade Phoenix
Join Date: Apr 2006
Location: Ontario, Canada
Posts: 38
|
results
Btw, I did the shared memory a couple days ago and it worked beautifully. Thanks.
dazz.
|
|
|
05-07-2006, 07:07 AM
|
#5 (permalink)
|
|
Anti-Zealot
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 72
|
Quote:
|
Originally Posted by dazz williams
Btw, I did the shared memory a couple days ago and it worked beautifully. Thanks.
dazz.
|
Ah, good to hear. Good luck with the rest of the project 
__________________
If you always think like an expert, you'll always be a beginner. | "A handful of knowledgeable people is more effective than an army of fools" -Writing Secure Code, 2nd Ed.
|
|
|
05-10-2006, 06:00 AM
|
#6 (permalink)
|
|
Registered User
Join Date: May 2006
Posts: 4
|
Looks like I'm late to the party, but sockets, IMO, are the greatest IPC method since sliced bread.
|
|
|
05-10-2006, 06:06 AM
|
#7 (permalink)
|
|
Anti-Zealot
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 72
|
Quote:
|
Originally Posted by tvqpriqphh
Looks like I'm late to the party, but sockets, IMO, are the greatest IPC method since sliced bread.
|
Yeah, assuming you aren't making large transfers via the sockets. The speedup of using SysV IPC (or similar) is huge.
In the benchmarks we did for large files, it would take 60 seconds or so to complete over sockets and about 10-15 seconds over IPC. Latency is lower over IPC as well. That's some empirical evidence for what is theoretically true.
Of course, sockets are more flexible and less prone to error, so it really depends on what you're doing.
__________________
If you always think like an expert, you'll always be a beginner. | "A handful of knowledgeable people is more effective than an army of fools" -Writing Secure Code, 2nd Ed.
|
|
|
05-12-2006, 12:59 AM
|
#8 (permalink)
|
|
Jade Phoenix
Join Date: Apr 2006
Location: Ontario, Canada
Posts: 38
|
Later on down the road in this project I really hope to implement some network communication between 2 computers each running the program (the "program" consisting of the 2 processes sharing memory), so there may me some socket programming of sorts after all. 
dazz.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Kaat a talking bot in c
|
nvictor |
Platform/API C++ |
10 |
05-19-2005 01:16 PM |
|
edit?
|
anon |
Lounge |
10 |
11-21-2002 03:02 PM |
All times are GMT -8. The time now is 10:33 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|