如何重新找回失去連接的tmux會話


錯誤描述:

不知道因為什么原因,tmux掛掉了。 顯示“failed to connect to server”消息
嘗試使用tmux ls 獲取當前正在運行的會話列表時。報錯

failed to connect to server: Connection refused

使用tmux時,無法重新連接。

$ tmux attach
no sessions

但是查看tmux 服務的時候,還是存在的。

$ ps -aef | fgrep -i tmux
hari     7139     1  1  2016 ?        2-20:32:31 tmux
hari    25943 25113  0 22:00 pts/0    00:00:00 fgrep --color=auto -i tmux

解決方案

這說明tmux服務器仍在運行,但是仍然顯示tmux ls failed to connect to server: Connection refused錯誤。 驗證了下屬於tmux會話的tmp目錄,並且lsof -p 7139 (tmux服務器的pid)顯示套接字文件已打開:

COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF       NODE NAME
tmux    7139 hari    5u  unix 0x0000000000000000      0t0 1712879255 /tmp/tmux-50440/default

也嘗試明確指定-S /tmp/tmux-50440/default為tmux,但沒有反應。
搜了一下, StackOverflow上的解決方案是 “Try sending SIGUSR1 signal to the tmux server process.”
嘗試將SIGUSR1信號發送到tmux服務器進程。
因為在tmux的文檔中也提到,發送SIGUSR1將使tmux重新創建套接字文件。嘗試了這種方法后,就能找到會話並重新連接了。

$ kill -s USR1 7139
$ tmux ls
0: 12 windows (created Mon Apr 18 21:17:55 2016) [198x62]

參考鏈接

  1. https://stackoverflow.com/questions/9668763/why-am-i-getting-a-failed-to-connect-to-server-message-from-tmux-when-i-try-to
  2. https://man7.org/linux/man-pages/man1/tmux.1.html
  3. https://timvisee.com/blog/reconnect-to-broken-tmux-session/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM