ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
anyway back to your question, im pretty sure that pipes block any read/write attempts unless there is exactly one read descriptor and one write descriptor open, hence after the fork() you have to close the appropriate descriptor before you can transfer data through the pipe. check out my links(in my profile page) for an ebook called Advanced Linux Programming, it has a chapter on pipes you can read to see if your doing stuff right.
Your code is a little ugly so I needed to do some changes to understand what you were trying to do. After understand it, I found you are improperly using an integer variable as the buffer pointer to your reads and writes. This code is still not behaving properly as its exit code is always different from zero but the child processes are working now.
kev << LOL if you think that was harsh u realllly don't know me :]
1) you have a buffer overflow. you can't ask the user to enter an index into an array without checking that value against the bounds of the array.
2) you dont check ANY functions for error returns. it's impossible to debug a program without error checking.
3) why are you dup'ing the pipes? there's no need for that, just read or write to them as necessary.