views:

250

answers:

1

I need to implement a handshake type protocol in to a small Linux program that uses named pipes to communicate with other processes. I've searched for a general implementation pattern for a handshake type protocol when using named pipes but I've not been able to turn anything up...

I simply can't believe that there isn't patterns to do this. Can someone point me to a possible resource?

In full disclosure this is for homework but implementing this pattern isn't the homework. We need to solve a problem within the homework code and I believe this to be a possible solution. The homework is implemented in C++ -- but the languages doesn't matter to me. I just don't want to reinvent the wheel....

Update: I have a feeling that this might be implemented with signals.

What I mean by handshake is that a child process reports to it's parent process that it is ready for work but does not proceed (even if there is something in the pipe) until the parent gives the go signal. In my working theory, I will have many child processes that need to report ready and wait for the go signal from the parent.

+2  A: 

In typical usage, the processes rely on blocking to handshake. The writer process opens the pipe for writing, the reader process opens the pipe for reading, and whichever happens first blocks until the other process opens its side. This can be extended to use nonblocking IO on the reader side.

Named pipes are most useful for one-to-one IPC. In your one-to-many situation, you should probably use a UNIX-domain socket instead.

caf
This homework has to do with named pipes.... So I'm stuck with the given architecture....
Frank V
Well, you really need one pipe per child process (two, if you want bidirectional communication). Given that, you can just have your parent process open all the pipes one at a time, and once all the open() calls have returned it knows that all the child processes are running and waiting for work.
caf
I think you are right.... Thank you for your reply.
Frank V