I'm having trouble reading/writing to a pipe between two unrelated processes, and its left me wondering if pipes can be used for interprocess communication among non-related processes. Here's the pseudo code for my IPC logic (its client-server based):
Server sets up a named pipe (fifo)
Client connects to server fifo
Client creates a private (anonymous) pipe.
Client sends the output file descriptor of this pipe to server.
Server creates a private pipe and sends output file desc to client
Now the server has the write end of the client's private pipe and the client has the write end of the server's private pipe, while both listen on their read ends, thus creating a two-way communication between client & server right?....
Apparently not in my case.
Here is the code that causes trouble:
(it differs from the pseudo in that I'm temporarily using a fifo to communicate back to the client)
/* create private pipe for input to server */
/* send client the filedes for write-end of pipe */
write(client_fifo, &priv_serv_pipe, sizeof(priv_serv_pipe));
fprintf(stdout, "\nprivate pipe created and sent");
/* read a client message from read-end*/
read(priv_serv_pipe, &msg, sizeof(msg));
fprintf(stdout, "\nmsg: %d", msg);
So far, the server succesfully communicates its file desriptor to the client, however the problem occurs when the client tries to write on that descriptor (no data is read by the server, and it continues to block on read). The client has no problems writing to the server's named fifo, so it leads me to believe that the client is incappable of writing on the server's private pipe. My question is, is it that only related process have permission to write on other processeses pipes? or am I simply doing something wrong here?
/* read write-end file descriptor for server pipe */
read(client_fifo, &priv_serv_pipe, sizeof(priv_serv_pipe));
/* send a message on write-end*/
write(priv_serv_pipe, &msg, sizeof(msg));
Thanks for any help.