LinuxQuestions.org
Help answer threads with 0 replies.
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 05-13-2010, 10:51 AM   #1
msaslin
LQ Newbie
 
Registered: Sep 2009
Posts: 9

Rep: Reputation: 0
IPC in C.


I have a question. I think that pipes are unidirectional and the other IPC facilities exist that can be used for bidirectional, like shared memory or POSIX message queues. I encountered error when used two pipes for bidirectional when buffers were longer, as it was ready for fd & read & write that was from another thing. I think that pipe is a FIFO, but I want to know how different they are implemented and how can it be better to use? If the mistake of me was it.
 
Old 05-13-2010, 11:36 AM   #2
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,773
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
I've been writing C on various platforms for many years. While that does not make me either an expert or all-knowing, I am not aware of any full duplex IPC* implementations. Remember that "full duplex" means that both ends of the connection are writing at the same time. Think of your data as a ping-pong ball and your IPC as a tube. If both ends insert a ball at the exact same instant, nothing appears at the other end. Any library that claims to be full duplex likely have two connections under the bonnet.

Two processes may open the same file as read-write. The application must have some protocol so that both process avoid trying to manipulate the same data at the same time. This protocol often involves record-level locking or some other mutex*.

Every time I have read or written code using pipes or fifos* or sockets, there has been a pair of connections -- read this one and write that one.

_________________
* IPC -- [i]nter-[p]rocess [c]ommunication
mutex -- [mut]ual [ex]clusion algorithm
FIFO -- [f]irst [i]n [f]irst [o]ut
 
1 members found this post helpful.
Old 05-13-2010, 03:12 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by SaintDanBert View Post
I've been writing C on various platforms for many years. While that does not make me either an expert or all-knowing, I am not aware of any full duplex IPC* implementations. Remember that "full duplex" means that both ends of the connection are writing at the same time.
...
If you have a single CPU/core system, simultaneous writing is physically impossible - the CPU is shared by the OS between the applications, so in any case just one application writes (and reads for that matter) at a time.

Still, the two applications may have two buffers in shared memory:

Code:
buffer1
buffer2
application1 writes to buffer1, application2 reads from buffer1;
application2 writes to buffer2, application1 reads from buffer2.

For that matter, the buffers may be not only explicit buffers in shared memory, but also named pipes:

man 3 mkfifo
man 1 mkfifo
.
 
Old 05-13-2010, 04:10 PM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
OP: I don't really understand what your question is, but (like most political commentators) that won't stop me adding my thoughts on this subject:

For me, TCP is basically always my preferred method of IPC. One program listens to connections on localhost, another connects as a client - full-duplex communications between two programs, easy. Plus, it makes it a trivial matter to extend either program to talk to a remote machine, even if they're running different operating systems or are a completely different architecture. You can even make it secure between two physically separate machines using tunnelling, and that can all be implemented from outside your program.

About the only thing this is unsuitable for is passing data at high speed (e.g. real-time audio) - even then, I'd almost always use TCP to pass information about shared memory segments (e.g. the key to use to access the shared memory) and to notify programs of updates to shared memory.

Just my two pence (I'm British).

Last edited by JohnGraham; 05-13-2010 at 04:13 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
Ipc gautam143 Programming 1 09-25-2007 04:50 PM
what is the best design(ipc) harvest Programming 2 10-03-2006 04:22 PM
IPC using NASM herbertgnanaraja Programming 1 08-21-2006 05:08 AM
IPC problem saturndude Mandriva 2 07-01-2006 09:50 AM
about IPC iclinux Programming 1 01-14-2005 11:16 PM

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

All times are GMT -5. The time now is 07:54 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