Here is my contrived use case: write a C program that hooks into stdout and stderr in order to passively examine those text streams before sending them along to the console as usual. Each time the string "hello" is found in text, increment a counter, and save that updated value in some arbitrary log file. This should monitor any program or process that writes to stdout/stderr.
It seems to me that this ought to be possible via /dev/ptmx or perhaps a bunch of dup/dup2 calls, but for the life of me I can't find clear documentation or a good example. It's more or less like telnetd only without the networking part. I've done a bunch of reading and I understand the Linux TTY a lot better than I had previously, but apparently still not well enough.
script
for an implementation that does something quite similar.