Κυλλήνη

Hint: reptyr

Hint from serverfault.

My office job routinely sees me connected to a Linux box via VNC.

Sometimes I start a remote job on the console, and realize later that it runs much longer than expected. (Should have started that one under Screen in the first place…)

I don’t want to keep my workstation running overnight just to keep the VNC session open; I would like to move that already-running remote job into a Screen session (on the remote box), so I can power down the workstation (and reconnect next morning).
DevSolar

Solution:
reptyr — A tool for «re-ptying» programs.

reptyr is a utility for taking an existing running program and attaching it to a new terminal. Started a long-running process over ssh, but have to leave and don’t want to interrupt it? Just start a screen, use reptyr to grab it, and then kill the ssh session and head on home.
«reptyr PID» will grab the process with id PID and attach it to your current terminal.

After attaching, the process will take input from and write output to the new terminal, including ^C and ^Z. (Unfortunately, if you background it, you will still have to run «bg» or «fg» in the old terminal. This is likely impossible to fix in a reasonable way without patching your shell.)