Jump to content
  • Advertisement
Sign in to follow this  
jostpuur

two way pipes in c

This topic is 3704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was writing a program which uses fork to split in two, and then pipes for communication between the processes. I was going to use a two way communication, so that the both processes both write and read. However, while writing the code, I had forgotten that the two directions actually use the same buffer. I started remembering this, when my program wasn't working, because the processes were reading their own writings out of the buffer. Now I've been struggling in trying to come up with some solution. I've deviced some semi-heuristic stuff that could maybe work, but it is starting to look ugly. Is there a standard solution to this problem? How to get two direction communication nicely and smoothly?

Share this post


Link to post
Share on other sites
Advertisement
You're using fork(), you must be on a POSIX system.

The idiomatic way of producing two-way communication over a forked calls is via a pair of pipes. See man pipe(2). Note that a pair of pipes means 4 file descriptors.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
You're using fork(), you must be on a POSIX system.

The idiomatic way of producing two-way communication over a forked calls is via a pair of pipes. See man pipe(2). Note that a pair of pipes means 4 file descriptors.


Perfect! This solves the problem.

Actually I had seen the manpage of the pipe. That's were I checked how to use it, but I mainly copied some commands from the example. The example doesn't involve a use of pair of pipes, so I didn't realize one could create more than one pipe when forking.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!