如何恢复“丢失”的屏幕会话?

如何恢复“丢失”的屏幕会话?

不知何故,我设法关闭了一个屏幕窗口,而屏幕没有“注意到”它,因此会话仍然被标记为attached.这会阻止我重新连接到此会话。我能做些什么?

me@iupr-serv8:~$ screen -r
There are several suitable screens on:
    25028.pts-19.XXX-serv8  (01/05/2012 07:15:34 PM)    (Attached)
    24658.pts-19.XXX-serv8  (01/05/2012 07:11:38 PM)    (Detached)
    24509.pts-19.XXX-serv8  (01/05/2012 07:10:00 PM)    (Detached)
    18676.pts-5.XXX-serv8   (01/02/2012 06:55:33 PM)    (Attached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
me@XXX-serv8:~$ screen -r 25028
There is a screen on:
    25028.pts-19.XXX-serv8  (01/05/2012 07:15:33 PM)    (Attached)
There is no screen to be resumed matching 25028.

[更新]

最后我发现,会话并没有丢失,只是第一个会话的ID是0。第二个会话有 ID 1

答案1

首先尝试使用 分离它screen -d。如果这不起作用,您可以按递增顺序尝试强调,

   -d|-D [pid.tty.host]
        does  not  start screen, but detaches the elsewhere running screen session. It has the
        same effect as typing "C-a d" from screen's controlling terminal. -D is the equivalent
        to  the  power  detach key.  If no session can be detached, this option is ignored. In
        combination with the -r/-R option more powerful effects can be achieved:

   -d -r   Reattach a session and if necessary detach it first.

   -d -R   Reattach a session and if necessary detach or even create it first.

   -d -RR  Reattach a session and if necessary detach or create it. Use the first  session  if
           more than one session is available.

   -D -r   Reattach a session. If necessary detach and logout remotely first.

   -D -R   Attach  here and now. In detail this means: If a session is running, then reattach.
           If necessary detach and logout remotely first.  If it was not running create it and
           notify the user. This is the author's favorite.

   -D -RR  Attach here and now. Whatever that means, just do it.

答案2

screen -r '1234.somescreensession'

屏幕上有一个:

1234.somescreensession(附件)

没有与 1234.somescreensession 匹配的要恢复的屏幕。

这是收回屏幕会话的简单方法。

screen -D -r '1234.somescreensession'

答案3

Write Failed: broken pipe当我附加了屏幕会话时,我的 ssh 连接意外关闭并显示消息后,我遇到了同样的问题。但是,我无法使用上述任何命令重新连接我的屏幕会话。请注意,我使用以下版本:

~> screen --version
Screen version 4.00.03 (FAU) 23-Oct-06

显然,仍然有一个sshd正在运行的实例,这使我无法分离和重新连接会话。在识别了PID的适当实例sshdkill对其进行了 ing 后,我能够使用 重新连接screen -r


仅供参考:您肯定会发现不止一个sshd恶魔,一个对应于您当前的登录名,另一个对应于过时的screen会话(实际上,可能有多个其他sshd正在运行的属于多个其他的screen)。

答案4

有时多个屏幕在后台运行。

可以通过以下方式恢复它们:

screen -r [pid]

要获取屏幕,首先运行screen -R,然后您将看到屏幕上所有正在运行的 PID,之后通过 恢复screen -r [pid]

相关内容