You SSH’d in and started a job that will run for hours. No tmux. No nohup.
Now you need to leave, and closing the window kills the process.
reptyr moves it into tmux so you can disconnect safely.
What reptyr Does
reptyr uses the ptrace syscall to re-attach a running process to a new terminal. It genuinely changes the process’s controlling terminal — not just redirecting I/O.
That distinction matters. Old gdb-based scripts like “screenify” can do something similar, but with three problems:
- The old terminal still delivers input to the process
- Window resize events don’t reach ncurses applications
Ctrl-Cfrom the new terminal doesn’t work
reptyr fixes all three because it actually replaces the controlling terminal.
Installation
| |
Basic Usage
| |
The process attaches to the current terminal and receives its input, output, and signals (Ctrl-C, Ctrl-Z all work).
The Common Scenario: Forgot to Start tmux
| |
When you reconnect:
| |
The process is still running, output intact.
The ptrace_scope Problem (Ubuntu)
Ubuntu 10.10+ disables non-root ptrace by default. reptyr will fail with:
| |
Temporarily allow it:
| |
Permanently:
| |
Or just run sudo reptyr <PID>.
ptrace_scopevalues: 0 = allow all, 1 = parent-only (default), 2 = root only, 3 = disabled. Setting it to 1 is enough for reptyr to work if you own the process.
Advanced: reptyr -l
| |
Creates a detached pseudo-terminal pair not connected to any shell. Useful for gdb:
| |
Cleaner than handing gdb your terminal directly.
When It Won’t Work
- Daemon processes: already detached from any terminal — nothing to re-attach to
- setuid binaries: ptrace can’t attach (security restriction)
- Dead processes: obviously not salvageable
Summary
Forgetting tmux isn’t fatal. reptyr <PID> moves a process from a dying SSH session into tmux in one command. disown it first to cut the shell’s hold, then open tmux and pull it in. On Ubuntu, adjust ptrace_scope as needed.
