Moving Running Processes to Tmux
A simple guide to moving a long-running process from your console to Tmux
In this article
If you have ever started a command in your server console that ran longer than you expected and you already needed to log out, here is a simple way to move the command to Tmux.
Installing dependencies
This guide uses commands that are not usually part of a basic Linux installation. They are easy to install, though – on Debian/Ubuntu it's as simple as this:
apt install tmux reptyr
Moving the process
- Suspend the process: press Ctrl+Z
- Resume the process in the background: bg
- Disown the process: disown %1
- Start Tmux: tmux or tmux attach (if you already have a tmux session running)
- Find the right PID: ps a | grep <$PROCESS_NAME>
- Restore the process in Tmux: reptyr <$PID>
The original procedure is taken from https://www.linkedin.com/pulse/move-running-process-screen-bruce-werdschinski/, and a tmux tutorial (in Czech) can be found, for example, on root.cz