How to move a running process from one terminal to another in Linux
This is one of those commands that I wished I knew years ago! Every system admin, developer, and user of Linux will at some point in time need to move a process from one terminal to another. Here's how to do it:
Prerequisite:
You will need to have reptyr installed on your system. Use "apt-get reptyr" on Ubuntu if it is missing
Process:
1. Pause your running process using CTRL-Z (note the process identifier, usually 1 unless you have multiple processes that you paused)
2. Start running the process in the background using bg %<process identifier> (i.e. if the process identifier was 1, then use bg %1)
3. Find the PID of your process using jobs -l
4. Using the PID and the disown command, detach your process from your terminal. If your PID was 1234 then the command would be disown 1234
5. Switch to the new terminal (or tmux session) where you want your command to run
6. Attach the PID to the new terminal using the reptyr <PID> command. For example, reptyr 1234
That's it, easy peasy lemon squeezy!