0

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.

4
  • There isn’t “a” standard output or standard error; each process gets its own standard output and standard error. Commented Jul 25, 2022 at 18:46
  • There's no single stdout or stderr, and not all stdouts and stderrs are connected to terminals (or consoles, or anything else in particular). You don't happen to mean you'd want to capture everything written to / from the terminal instead?
    – ilkkachu
    Commented Jul 25, 2022 at 19:07
  • 1
    You might want to take a look at script for an implementation that does something quite similar. Commented Jul 25, 2022 at 19:11
  • Oh, I see. So to achieve this objective, I could potentially replace /dev/tty or teh terminal driver. But in any case, it wouldn't happen in userland.
    – mszinger
    Commented Jul 25, 2022 at 19:26

0

You must log in to answer this question.

Browse other questions tagged .