Not really.
The closest you could get is:
Start a new screen window, run:
trap '' INT HUP
exec sleep 99999999
in it. Record the tty for that window ($tty
).
Use lsof
to figure out what fds of what processes in the session are open to the current tty.
With gdb, attach to every process in the session, do some call signal(1,1)
to ignore the SIGHUPs. For the session leader, you'll probably need to do a call dup2(0,1023)
(assuming 0 is opened on the tty) to keep a fd open on the old terminal. Then for each process, do
set variable $fd = open("the-screen-window-tty",2)
Then for each fd that was open on the old terminal, do:
call dup2($fd, that-fd)
And then:
call close($fd)
detach
The session attached to the new terminal would be the one with that "sleep" process as the leader (and only process) though, things like window resizing, CTRL-C, CTRL-Z, job control, /dev/tty won't work and probably a few more nasty side effects I don't think of.
If on Linux, reptyr, brought up by @angus in a comment to your question, automates that process and addresses the shortcomings above by creating a new pty and make that controlled by the process you want to migrate. However, it only supports migrating one process AFAICT.