This image shows how pseudo-terminals work:

enter image description here

If I have two terminal emulators open, I can send the string "Hello" from the first terminal emulator to the second terminal emulator:

echo "Hello" > /dev/pts/1

When this command is executed, the string "Hello" will travel from the slave side of the second pseudo-terminal to the master side of the second pseudo-terminal and then gets displayed on the second terminal emulator.

Now is it possible to send data in the opposite direction, that is, to send data to the shell instead of the terminal emulator (or the process that the shell is running)?

  • 1
    The TIOCSTI ioctl might be relevant (assuming you have root or the appropriate capability set)... – thrig May 15 '17 at 21:16
  • 1
    I think this question has been asked several times (can't find them ATM), and so answer so far has been "no easy way to fake input to the shell". – dirkt May 16 '17 at 7:20
  • 1
    Are you trying to run commands in the other terminal, or just dump text data there? The write, talk, and wall (as in "write to all") command line programs can do that. – Adam Katz Aug 31 '17 at 18:41

Each proccess has 3 default "file descriptors"

0 is stdin  (standart input)
1 is stdout (standart output)
2 is stderr (standart error output)

You need to find PID of shell process and then you can do following:

echo "test" > /proc/{your_shell_pid}/fd/1

This will print test in the shell process' standart output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.