Most commonly, this is done in the way that, say, "the bash 'pipe' ("|") operator does it." You simply arrange for the STDOUT and/or the STDERR handles of the child to be directed to a pipe, then open and read the pipe.
Although pipes "appear to be 'files,'" and can in fact be referred-to by names, they are actually inter-process communication queues that can be manipulated using ordinary fopen/fclose/fread/fwrite/fctl primitives "as though they were files."
Thus: "pipes, therefore also coproc," are(!) "the right way to do it," and "disk files" (despite the possible presence of 'file names,' and the apparent use of file-I/O primitives) are not actually involved.
A pipe, as I said, is a queue. When a reader reads, it is ordinarily "blocked" (put to sleep ...) until data is available to be read. Similarly, when a writer writes to a "full" pipe, it is blocked until the pipe is no longer full. All of this synchronization is completely invisible to the processes, who, so far as they can tell, are simply using "files." The idea was quite magical in the 1970's, and it's still quite magical today.
Last edited by sundialsvcs; 02-14-2016 at 07:58 PM.
|