How to use the command reptyr (with examples)
- Linux
- December 25, 2023
The reptyr
command is used to move a running process to a new terminal. It is particularly useful when you forget to start a long-running task in screen
, a terminal multiplexer tool. reptyr
allows you to transfer a process from one terminal session to another, preserving its current state.
Use case 1: Move a running process to your current terminal
Code:
reptyr pid
Motivation:
Sometimes, we may accidentally start a long-running process in a terminal session without using a terminal multiplexer like screen
or tmux
. In such cases, if we need to detach from the terminal or need to close it, the process will be terminated. To avoid this, we can use the reptyr
command to move the process to the current terminal, allowing us to detach from the original terminal session.
Explanation:
reptyr
: Thereptyr
command is used to move the process from the original terminal to the current one.pid
: Thepid
parameter represents the Process ID (PID) of the process you want to transfer.
Example output:
Suppose we have a long-running process with a PID of 12345 that is currently running in a different terminal session. To move this process to the current terminal, we would use the following command:
reptyr 12345
On executing the command, the process with PID 12345 would be transferred to the current terminal session. You would then be able to detach from the original terminal without terminating the process.
Conclusion:
The reptyr
command is a valuable tool for moving running processes to new terminal sessions. It allows you to transfer a process from one terminal to another, preventing the termination of long-running tasks when closing or detaching from a terminal session. With its simple syntax, it provides a convenient way to continue managing and monitoring processes that were mistakenly started in the wrong terminal.