LinuxQuestions.org
Review your favorite Linux distribution.
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 06-20-2010, 05:29 AM   #1
Khaj.pandey
LQ Newbie
 
Registered: Apr 2010
Posts: 12

Rep: Reputation: 0
IPC Mechanisms


Hi,

I am trying to understand which IPC mechanism should be preferred over another. I have read up a deal of it on Beej's guide & a book i picked up recently (UNIX Systems Programming: Communication, Concurrency and Threads).

While each of these books do a wonderful job of explaining of how to setup & use each of the IPC mechanisms; they do not touch on performance implications of the same.The interwebs is not helping either.

Well it's obvious that a mechanism like socket will be used if the system is distributed , but what is the case when the processes reside on the same system?

I.e Mainly , i am looking for advantages/disadvantages between the following mechanisms :

- Named Pipes
- Message Queues
- Shared Memory
- Local Sockets

I would love it if you guys can give some practical scenarios where you have encountered them & any reason why one should be preferred over another. All examples i have come across are typical process A writes int and B reads it.

Also apart from access to shared memory/hardware resources , is there any other reason where semaphores are used?

Cheers!
 
Old 06-20-2010, 12:07 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Khaj.pandey View Post
Hi,
...
Well it's obvious that a mechanism like socket will be used if the system is distributed , but what is the case when the processes reside on the same system?
...
Sockets work well on a single CPU system as well.
 
Old 06-20-2010, 01:13 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi - I would add to your list:
Quote:
- Named Pipes
- Message Queues
- Shared Memory
- Sockets (all)
- Signals
Quote:
Q: is there any other reason where semaphores are used?

A: Sure. Semaphores (or *any* mutex) can also be used like "signals" - it provides an efficient way for a process to block ("wait") until somebody else releases the semaphore ("signals" the process - without having to use actual signals).
If all the processes are on the same system (and you're CERTAIN that over the lifetime of your application, they will all REMAIN on the same system), you could always consider a threads API instead of IPCs.

But don't be bashful about using AF_INET sockets - they can be *very* efficient. And don't be too eager about using UNIX sockets. They're great - when you need them. But they can over-complicate your code, and reduce portability, if you use them in places where you DON'T really need them. "The right tool for the right job" and all that

'Hope that helps .. PSM
 
Old 06-20-2010, 01:32 PM   #4
Khaj.pandey
LQ Newbie
 
Registered: Apr 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks guys!

Interesting use of a semaphore paul ,never would have thought of it

Correct me if i am wrong , threads API would be used provided the process is the same ... i.e. as i now dwell over it in despair... I see message queues are async as opposed to pipes. So that a differentiating factor. Is there any restriction on the data sent over sockets ? i.e. safe to send both binary & stream data ?

And again paul , you are on the mark, I wanted to actually see more examples where IPC is the way to go... as i mentioned earlier all the examples i see are process A writes Integer, Process B reads it. Hoooray for IPC!

Last edited by Khaj.pandey; 06-20-2010 at 01:34 PM.
 
  


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
beehive: Is it possible to use other authentication mechanisms? eantoranz Linux - Software 0 10-07-2008 12:45 PM
linux locking mechanisms psrs Linux - General 2 04-08-2005 01:19 PM
IPC Mechanisms ananthbv Programming 5 12-20-2003 11:57 AM
Using different transport mechanisms hypernetics Linux - Networking 0 12-07-2003 10:04 AM
parameter passing mechanisms dhanakom Programming 2 09-01-2003 04:15 PM

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

All times are GMT -5. The time now is 06:36 AM.

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