Transfer current command to a detachable session (tmux/screen)
Solution 1:
This works, most of the time:
Prerequisites: have reptyr
and tmux
/screen
installed; you'll be able to find them with apt-get
or yum
, depending on your platform.
Use Ctrl+Z to suspend the process.
Resume the process in the background with
bg
-
Find the process ID of the background process with
jobs -l
You'll see something similar to this:
[1]+ 11475 Stopped (signal) yourprocessname
Disown the job from the current parent (shell) with
disown yourprocessname
Start
tmux
(preferred), orscreen
.-
Reattach the process to the
tmux
/screen
session with reptyr:reptyr 11475
Now you can detach the multiplexer (default Ctrl+B, D for
tmux
, or Ctrl+A, D forscreen
), and disconnect SSH while your process continues intmux
/screen
.Later when you connect with SSH again, you can then attach to your multiplexer (e.g.
tmux attach
).
Solution 2:
reptyr
is good but I got a permission error
$ reptyr 30622
[-] Unable to open the tty in the child.
Unable to attach to pid 30622: Permission denied
Then found-L Like '-l', but also redirect the child's stdio to the slave.
which worked like a charm
$ reptyr -L 30622
Opened a new pty: /dev/pts/4