Jür*_*aul 52 shell command-line gnu-screen tmux
我目前正在运行备份,现在需要将其转移到可拆卸的,例如 ontmux或screen。当命令当前正在运行时,有没有办法做到这一点?
我可以通过按Ctrl+将命令发送到后台,Z然后通过发出fg命令将其恢复。但我不知道当我退出终端时该会话是否可以返回。
Vil*_*lle 60
这在大多数情况下有效:
先决条件:有reptyr和tmux/screen安装;您可以使用apt-get或找到它们yum,具体取决于您的平台。
使用Ctrl+Z暂停进程。
在后台恢复进程 bg
找到后台进程的进程ID jobs -l
你会看到类似的东西:
[1]+ 11475 Stopped (signal) yourprocessname
Run Code Online (Sandbox Code Playgroud)从当前父级(外壳)中取消作业 disown yourprocessname
开始tmux(首选),或screen。
使用 reptyr将进程重新附加到tmux/screen会话:
reptyr 11475
Run Code Online (Sandbox Code Playgroud)现在您可以分离多路复用器(默认为Ctrl+ B、Dfortmux或Ctrl+ A、Dfor screen),并在您的进程在tmux/中继续时断开 SSH 连接screen。
稍后当您再次使用 SSH 连接时,您可以连接到您的多路复用器(例如tmux attach)。
reptyr很好,但我遇到了权限错误
$ reptyr 30622
[-] Unable to open the tty in the child.
Unable to attach to pid 30622: Permission denied
Run Code Online (Sandbox Code Playgroud)
然后发现
-L Like '-l', but also redirect the child's stdio to the slave.
这就像一个魅力
$ reptyr -L 30622
Opened a new pty: /dev/pts/4
Run Code Online (Sandbox Code Playgroud)