This is an amazing Linux trick that enables you to steal a process’s terminal output and reconnect it to another terminal session. Reptyr can perform ‘re-pty-ing’ of any process in Linux and thus makes it possible to detach a process from one PTY/TTY terminal session and attach it to another. The idea makes use of the ‘leading terminal’ concept, which is key to Linux. As such, every process in a session has the same controlling terminal, and each terminal belongs to at most one session. If a terminal fails, its child process is killed too, which is best avoided.
Perhaps the best example is running something inside an SSH session and getting disconnected. Reptyr enables you to leave the child process running even if its host terminal is killed. That’s a fairly common situation: you may want to reboot the server or disconnect from the SSH session and go home without losing things that were running in the terminal. Let’s take a look at the example. We’ll run a conversion command inside an SSH session, something like this: