reptyr, linux processes and wtfpl

Date: 2026-05-16

I have a bad habit of installing things and not try them when I intend to. In the past few days I've been trying out different agents and harnesses to find out what the hype was all about, when I realised I could use tmux and let my laptop go to sleep. Yet, I only realised I could've done that after starting a session.

I wondered if there was a way to pull the agent session under tmux, and that's when I found reptyr.

reptyr is a tool that lets you move a running process to a new terminal, and all you have to do is run reptyr <pid> in the terminal you want it to.

Naturally, I was interested in knowing how it works, so I dug into the blog post explaining it: https://blog.nelhage.com/2011/02/changing-ctty/

It uses ptrace to attach to the process, then fork to get a child process. This child process is also traced, then setpgid to put it into it's own process group. The parent process is then setpgid to the child process group, then detaches using setsid by moving into a new session. Finally, we can use ioctl with TIOCCTTY to set the controlling terminal of the process.

I'd also found neercs and injcode that perform the same trick. (These are taken straight from the blog of the author :P)

While looking at neercs though, I found a new license I've never seen before: WTFPL