IPC Mechanisms


 
Thread Tools Search this Thread
Top Forums Programming IPC Mechanisms
# 1  
Old 06-19-2010
IPC Mechanisms

Hi!

I wanted to know the advantages / disadvantages of different IPC mechanims such as sockets, pipes (unnamed) , shared memory & message queues.

Pipes for example i hear are fast , but are difficult to debug as compared to sockets.

Can you guys please name some situations where one is prefered over the other?

Thanks!
# 2  
Old 06-19-2010
Quote:
Can you guys please name some situations where one is prefered over the other?
That's a broad, open question - it almost sounds like an essay for homework.

Either way, if you have a look at the introduction to each section in Beej's guide to Unix IPC, that should give you a decent background in all the standard methods of IPC, and I'm sure you can "compare and contrast" (or whatever) in your own head.

Please come back if there are any specifics you'd like to know/aren't sure about.
# 3  
Old 06-20-2010
LOL ! School ended about 3 years ago. I have been working with C++ for about 3 years; i am actually trying to gain knowledge of system programming by either R&D or by Q&A. I'll run through the beej's guide.... thanks!

The reason i asked is , the book i am refering explains each mechanism well, but it does not say when to prefer one over the other.....

God i wish school was still on Smilie

Cheers!

---------- Post updated 06-20-10 at 05:13 AM ---------- Previous update was 06-19-10 at 12:21 PM ----------

So i did go through that article, picked up a book on my way home (UNIX Systems Programming: Communication, Concurrency and Threads). They both do a wonderful job of explaining each of the IPC mechaisms...setting up keys, calling ctl/op functions... & destroying them.... Yet there is no mention of any performance implication or suggestion of when each of these should be preferred. So i have to ask again... are there any specific subsets of problems where one should be preferred over another.... i.e. for example whats stopping one from using named pipes as opposed to message queues?
# 4  
Old 06-20-2010
Well, let's take a look at some situations where these things are used...

Shared memory avoids having to write data into and read it back out of the kernel, making it a blindingly fast way to share the same data with swarms of processes. Since it's not arbitrated by the kernel, it's got race conditions and pitfalls, so isn't as easy as it looks; when solving a complex enough problem you might find you're writing your own sockets from scratch instead of anything faster. You see it in situations with very demanding performance requirements, like high-performance audio or video interfaces(X11 drivers, XSHM video, DirectX). Linux's modern pthreads implementation builds mutexes and the like out of atomic operations on shared memory.

Named pipes are kind of an old-fashioned hack kept for portability reasons. Their behavior can be a bit obscure when dealing with more than one reader and/or writer. Occasionally handy in the shell to bridge unbridgables, otherwise I don't see them get much serious use.

UNIX domain sockets are very often used for local client/server interfaces because they're network-like(one server, multiple clients) without the overhead of loopback networking. Big things like X11 and MySQL servers serve clients with UNIX domain sockets when possible. Lots of less demanding system daemons and controllers(system loggers, linux udev, linux acpid, linux's wpa authentication manager) also use UNIX domain sockets for their convenience of network-like connect/disconnect without the complication of actual networking. They can't do any kind of sharing or broadcast sending.

pthreads is a threading implementation but often called (and used as) IPC anyway. Some implementations do allow seperate processes to share mutexes etc(the current NPTL linux implementation), some don't(linux's old linuxthreads implementation). Its features are tightly defined, fairly portable, and somewhat limited, mostly restricted to control mechanisms, not communication structures. By and large its overhead is quite low, but implementations of course vary. For simple control of threads it's difficult to beat.

System V IPC seems a bit overbuilt. Unlike POSIX thread primitives, this API is geared towards communications between unrelated processes, and frilled with so many features it's hard to imagine it not having significant overhead(most objects semi-persistent and given their own owner/group/attributes set, mtimes kept for many kinds of things, sometimes even last-user-modified). It has some interesting and difficult-to-implement features(grouping several semaphore operations atomically) which would be useful if implemented brilliantly, but can stall and starve if done badly, and implementations do vary. Message queues I'm unfortunately quite unfamiliar with.

Last edited by Corona688; 06-20-2010 at 04:13 PM..
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 06-23-2010
Thanks corona... that was a fantastic reply.

Cheers!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Questions about IPC

Hello and thanks in advance for any help anyone can offer to help me understand this I'm curious about a 30.000 ft view on how IPC works in Linux between parent-child processes...I understand there's multiple types of IPC's... But I'm currently trying to figure out if parent-child process IPC... (1 Reply)
Discussion started by: bodisha
1 Replies

2. Shell Programming and Scripting

Are there any IPC mechanisms in cygwin?

I wonder are there any IPC mechanisms in cygwin? such as shared memory, semaphores , message queues and piping? Thanks Jack (2 Replies)
Discussion started by: lucky7456969
2 Replies

3. Shell Programming and Scripting

help with IPC + thread

Actually i am thinking of some usefull application that involves both IPC and pthreads.But i am not quite sure what type of application involves both these together :confused:. Anyways i am now working on creating a simple featured file manager that can do the following: Display file name and... (2 Replies)
Discussion started by: ronmaximus
2 Replies

4. HP-UX

IPC settings on HP-UX

Hi Experts, Need your help for checking te interprocess communications settings on HP-UX box. Using ipcs command I am able to view Message queue,semapohores etc, but from that output I m not able to understand how to determine if there is any issue with ipc settings and how to resolve that? (1 Reply)
Discussion started by: sai_2507
1 Replies

5. UNIX for Dummies Questions & Answers

Mach IPC

hey everyone, I'm reading a tutorial on the Mach kernel principles, however, the port and port rights part are kind of confusing to me. I don't know if the book has typos or something but it seems a bit contradictory. It says that "ports, themselves, are not named. It is the port rights that are"... (10 Replies)
Discussion started by: neur0n
10 Replies

6. Solaris

errors on Netra-440: "IPC Warning: ipc: tcp_protocol: bad magic number"

I was asked to look into a problem with a Sun Netra 440 in another department. On the server in question, the relevant 'uname -a' information is, "SunOS host1 5.9 Generic_118558-16 sun4u sparc SUNW,Netra-440". That information aside, while the other admin is logged into the ALOM, these errors are... (0 Replies)
Discussion started by: Borealis
0 Replies

7. Programming

IPC with PIPE

Hi guys, I'm new to Linux and Unix I have just simple code . But I don't know why it doesn't work .. But, the outputfile is Blank.. I don't understand why.. Please help me.. Thank you very much P.S: sorry, I don't know how to edit this post clearly.. it's hard to read.. Please try.. (2 Replies)
Discussion started by: thanh_sam_khac
2 Replies

8. UNIX for Dummies Questions & Answers

Ipc Details

hai, i am doing my masters degree in computers.please any one tell me about fork(),semaphores,mutex,messaging queues,messaging using pipes ,and msgget(),msgrecv() funtions in ipc programming . i have exam on that i have a book but in that they not given clearly. hope u will ... (2 Replies)
Discussion started by: G.Vishnuvardhan
2 Replies

9. UNIX for Dummies Questions & Answers

Data Transfer programs in IPC Mechanisms??

I have no IPC Mechanisms program which includes data transfer on the same Linu machine. All mechanisms of IPC must be tested. If anyone have programs about it, could you send to me?? I am waiting your answers. please help me...!!!! (2 Replies)
Discussion started by: boris35
2 Replies

10. UNIX for Dummies Questions & Answers

Ipc

I have a parent that is passing data to child A and then child A has to process it and pass to child B. I am able to pass the data to child A but am not able to pass it to child B. Child B seems to only be receiving the last data instead of the whole data. I saw one example in a book but it uses... (1 Reply)
Discussion started by: scmay
1 Replies
Login or Register to Ask a Question