Sample Header Ad - 728x90

How to write to terminal device stdin of running process from a different terminal without any prior preparation?

0 votes
2 answers
970 views
There seem to be plenty of similar questions, for example: https://stackoverflow.com/questions/5374255/how-to-write-data-to-existing-processs-stdin-from-external-process However the answer given is to prepare the program beforehand by making its stdin a pipe. There's also: https://serverfault.com/questions/178457/can-i-send-some-text-to-the-stdin-of-an-active-process-running-in-a-screen-sessi Which is answered by commanding a terminal multiplexer under which the program in question is running. That means it also needs prior preparation. This question is about how to do this *without* having done any preparation beforehand. At first I thought it might be as simple as:
echo foo > /proc/$p/fd/0
but that just writes to the terminal. So then I tried:
echo foo > /proc/$terminal_emulator/fd/$ptmx_fd
but that also fails because it just opens up a new terminal device slave for echo. I already have an answer using gdb (*sigh*) which I'll be posting below, but I wonder if anyone knows of a simpler and better alternative.
Asked by JoL (4989 rep)
Aug 6, 2019, 05:06 PM
Last activity: Aug 6, 2019, 05:53 PM