ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
can ne1 plz say why is this getting into infinite loop its supposed to take n integers and search for a number in 2 child process if found the child returns index else they return -1
as infamous41md points out above(quite harshly) your code would be easier to read if it were formatted in some way but as this is your first post i think we can be quite forgiving.
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.
Hi beginner_84,
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 :]
OP <<
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.