Query whether a pipe is empty AND has a reader waiting?
by jsyjr from LinuxQuestions.org on (#6H4W4)
I have long dreamed of recreating, within Emacs, the input and transcript functionality of the Apollo DM (Display Manager):
The distinguishing characteristic of a DM transcript was that, even in the presence of typeahead, it recorded faithfully and immutably, from the child process's perspective, the interleaving of input consumed from stdin with output written to stdout. (Of course, in the absence of typeahead, creating such a transcript is trivial.)
The essential implementation hurdle then is handling typeahead. And that comes down to being able to ask whether the pipe supplying stdin is both (1) empty and (2) has a read waiting.
So my question is, can one do that from userspace on a contemporary Linux kernel?
The distinguishing characteristic of a DM transcript was that, even in the presence of typeahead, it recorded faithfully and immutably, from the child process's perspective, the interleaving of input consumed from stdin with output written to stdout. (Of course, in the absence of typeahead, creating such a transcript is trivial.)
The essential implementation hurdle then is handling typeahead. And that comes down to being able to ask whether the pipe supplying stdin is both (1) empty and (2) has a read waiting.
So my question is, can one do that from userspace on a contemporary Linux kernel?