LoginSignup
15
7

More than 5 years have passed since last update.

screen -r で attach できないときの対処

Posted at

screen を使用中にクライアントから通信を切断したりした場合などに、セッションは残っているが Attached となっていてそれをそのまま attach できなくなることがある。

$ screen -ls
There are screens on:
        11119.pts-8.ip-10-10-10-10        (Attached)
        11520.pts-1.ip-10-10-10-20        (Detached)
2 Sockets in /var/run/screen/S-foobar-user.

$ screen -r 11119.pts-8.ip-10-10-10-10
There is a screen on:
    11119.pts-8.ip-10-10-10-10  (Attached)
There is no screen to be resumed matching 11119.pts-1.ip-10-10-10-10.

このような場合には attach したい pts のプロセスを kill してやるとよいです。

(pts とは接続している仮想端末のこと)

ps aux|grep pts|grep sshd で attach したい pts/N のプロセスを探します。

$ ps aux|grep pts|grep sshd
foobar-user 12393  0.0  0.0 111576  1992 ?        S    15:53   0:00 sshd: ec2-user@pts/8
foobar-user 12685  0.0  0.0 111576  1992 ?        S    16:10   0:00 sshd: ec2-user@pts/0
foobar-user 12788  0.0  0.0 114500   896 pts/0    S+   16:12   0:00 grep sshd

この場合、pts/0 は grep で使っているこのシェルなので今回は pts/8 のプロセスを kill します。

$ kill 12393

attach します。

# Attach したいセッションが(Detached) になっていることを確認
$ screen -ls

# attachする
$ screen -r 11119.pts-8.ip-10-10-10-10

これで attach できるようになりました。

Ref

15
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
7