How can I switch between ttys without using screen?

Maybe these schema can clarify the situation. This is the usual setting:

                               Terminal  (/dev/ttyX or /dev/pts/x)
                                device
                                   |
                    (screen)<--[<output]----x-------(stdout) Process1
        Terminal  (keyboard)---[input >]---o-\----->(stdin)
                                            \ \
(hardware console or                         \ `----(stdout) Process2
 virtual console or terminal                  `---->(stdin)
 emulators like xterm, …)

And there is no way to plug some new Process3 like this:

                             Terminal
                              device
                                 |
             (screen)<---o---[<output]--x------(stdout) Process1
  Terminal (keyboard)---/-x--[input >]-o-\---->(stdin)
                       | /              \ \
                       | |               \ `---(stdout) Process2
                       | |                `--->(stdin)
                       | |
                       \ `---------------------(stdout) Process3
                        `--------------------->(stdin)

What screen (and others) does is allocating some pseudo terminal device (like xterm does) and redirect it to one or more "real" terminals (physical, virtual, or emulated):

             Terminal                   pseudo
             devices              ,--> Terminal (/dev/pts/x)
                |         _______/      device
Terminal <--[<output]--- |       |        |
 1       ---[input >]--> |screen | <--[<output]---x-----(stdout) Process1
                         |Process| ---[input >]--o-\--->(stdin)
Terminal <--[<output]--- |       |                \ \
 2       ---[input >]--> |_______|                 \ `--(stdout) Process2
                                                    `-->(stdin)

Using screen -x you can attach one more terminal, xterm, whatever (say Terminal 3) to the screen session.

So no, you can't communicate directly through stdin/stdout with processes attached to a different terminal. You can only do so through the process that is controlling this terminal if it happens to be a pseudo terminal, and if this process was concieved to do so (like screen is).


Reconnecting the processes on the other terminal to your current terminal is not possible without dirty tricks. It is possible by forcing the process to perform certain system calls (with ptrace); this causes some programs to crash. There are several tools that do this, such as neercs, retty, cryopid, reptyr, …; see How can I disown it a running process and associate it to a new screen shell? and linked questions.

Obtaining the output already displayed on the other terminal is a different problem. There is no fully general solution: in principle, once the output has been rendered, the terminal might store it only as an image. In practice, all X terminal emulators keep their output buffer in text form so that you can copy-paste it. The way to grab that output depends on the terminal emulator; the basic idea is to simulate selecting the whole scrollback buffer. For a Linux console such as /dev/tty1, the scrollback buffer is easily available as /dev/vcs1 (and /dev/vcsa1 with text attributes).

The simple answer is that if you want to reconnect to a terminal from a different place, use screen or tmux.