Tool tip: reptyr, for the forgetful shell user

Have you ever started a long-running command, only to realize that you did not start it inside tmux or screen?

I have. It is especially annoying over SSH, where closing the terminal, or simply losing the connection, can also end the command. This can even have unwanted and serious side effects.

In this case, reptyr can help. It attaches an already-running program to the terminal you are currently in.

The usage details can be found in the README of the project.

TL;DR: Disown the process, get the PID and run reptyr <PID> in tmux or screen.

The process is now attached to that tmux terminal. You can detach from tmux and come back later as usual.

One useful note: if the command has subprocesses, try -T instead:

reptyr -T <PID>

This transfers the complete terminal session, including the processes running in it.

It is still better to start important commands in tmux in the first place. But when you forget, reptyr is a nice tool to have in your toolbox.


If you find this page useful, donate a coffee to the C++ user group of Stockholm, SwedenCpp