When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
2 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
There are two problems I see here:
1 - i isn't initialized in read_pipe
2 - You call pipe in both the parent and child1.
When you fork, the child inherits the parent's descriptors. What you're doing here is opening a set of descriptors in the parent, then doing the same again in child1. So the data you write in child1 can never be seen by anyone else. child2 however inherits the parent's descriptors, but there's nothing to read.
This one is more of a nit, but assuming that error_kill doesn't return what's the point of the else? Why not just have:
if (p1 < 0)
error_kill(...)
/* We can't get here if there was an error since error_kill doesn't return */
if (p1 == 0) // child
...