Ever started a long-running process in an SSH session and then realized your connection might drop? The reptyr utility lets you move a running process to a new terminal or screen/tmux session.

Installation

# Debian/Ubuntu
apt install reptyr

# MacOS
brew install reptyr

# Fedora/RHEL
dnf install reptyr

Usage

Follow these simple steps:

  1. Find the PID of your long-running process:

    ps aux | grep your-process-name
    
  2. Start a screen or tmux session:

    screen -S rescued-process
    # or
    tmux new -s rescued-process
    
  3. Move the process to your new session:

    reptyr <PID>
    
  4. Done! You can now detach from the session without killing the process.

If you get “Operation not permitted” errors, you might need to temporarily adjust the ptrace protection:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
# Remember to restore security after:
# echo 1 | sudo tee /proc/sys/kernel/yama/ptrace_scope