using only one pipe for n processes (C programming)
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.
Please wrap your code and data snippets inside [CODE]...[/CODE] tags. Doing so will preserve indentation and provide other visual clues which make it easier for others to comprehend. You may write those yourself as shown, or use the # button available with Advanced edit options. (A complete list of BBCode tags is always available via a link near the bottom of every thread view).
Although everyone here is willing to help, it is generally preferred that you attempt to understand your problems first, then ask for specific help when you get stuck, providing any error messages you cannot resolve along a short description of what you have done so far to try to understand and fix it.
Asking others to evaluate and debug code without further explanation may not attract the most helpful answers.
That said, the blog post linked by rtmistler looks like an excellent place to start, and one I had not previously seen!
Ofcourse. I can, i have a process and splitting the process into child again and again for until it becomes n processes using fork and then using pipe to connect every process using only one pipe
Have you used a debugger to follow the first process to confirm it does what you want, and the done the same with child #1?
How about have you printed out the pipe handles and/or the addresses of the descriptors, along with doing same for all the pids?
All of you've done is to ask a question for people to do that effort for you and provide you with the answer.
The code looks reasonable, not sure you need the dup's or to close descriptors unless you're making them all daemons. If it were me, I'd avoid any complications and use either debug method described above, but since they're there, then confirm they work properly, again using debug methods.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.