我不相信有没有像屏幕的东西是可能的。一旦你的伪TTY丢失了,我几乎可以确定它不能从一个不同的shell中恢复(至少不是没有一些简单的黑客攻击)。
只要添加一个现有的过程到一个新的屏幕,我认为这是可能的。这里尝试说明:http://monkeypatch.me/blog/move-a-running-process-to-a-new-screen-shell.html
The first thing to do is to suspend the process. In my case, Irssi can be suspended by typing ctrl+z.
Secondly, resume the process in background:
$ bg
Now, we will detach the process from its parent (the shell). So, when the parent process will be terminated, the child (Irssi) will be able to continue. For this, we use the disown builtin:
$ disown irssi
Launch a screen session:
$ screen
As we are in a screen session, we will retrieve the irssi process. To do so, we use the reptyr command which take a pid:
$ reptyr <pid>
To avoid the tedious pid research, we can use the pgrep command:
$ reptyr $(pgrep irssi)
Now the process is in a screen shell, we can safely detach our session and no longer worry about killing our X server or close our ssh connection.
You'l需要reptyr这一点。
选项2:
我怀疑你可能试图解决错误的问题。如果您的SSH连接正在丢失,为什么不解决该问题?您可以通过调整连接设置来将SSH设置为非常容忍超时和断开连接。
在您的客户端,在$HOME/.ssh/config
加:
ServerAliveInterval 60
ServerAliveCountMax 5
现在,即使服务器没有5分钟响应您的会话将不会超时。
出于好奇,为什么你不想调用屏幕? – SpliFF
@SpliFF通常不是我不想,但仅仅是因为我在问题中说过了太迟了(意外断开或意识到我需要在中途会话中使用屏幕)。顺便说一句,屏幕也打破腻子和iterm的滚动回滚,允许通过拖动滚动条轻松滚动,也许它可以调整?但我懒得解决这个问题。 – lyu