I'm trying to understand this this answer. Especially, how does data flow across processes?
I assume that input stream flows through a child's input through output connected with pipe, then is collected by a parent through pipe output. However, before the new turn of the loop and executing the command in a child, what does happen to the read data?
Is data buffered inside the parent process (somehow? I'd like to know what's responsible for that), and later this buffer is copied and passed to a child after fork()
, then the child passes the saved input to the exec()
?
EDIT - additional aspect:
(In the example I've presented, the new pipe is created with every turn of the loop and filled with new descriptors, when pipe()
is called. I've created a working modification, where the table of descriptors is created outside the loop and repopulated. How does it affect the previously read data from previously executed command? Where it is stored, when the new pipe is created and new file descriptors are stored in the reused table?)