# reptyr: Changing a process's controlling terminal

DevFeed: [reptyr: Changing a process's controlling terminal](<https://devfeed.tech/articles/reptyr-changing-a-process-s-controlling-terminal-21928.md>)

Original publisher: [Read original article](<https://blog.nelhage.com/2011/02/changing-ctty/>)

Author: Nelson Elhage

Published: 2011-02-08T23:06:50Z

Content type: article

Language: en

Sources: [Nelson Elhage](<https://devfeed.tech/sources/nelson-elhage.md>)

Topics: [Process](<https://devfeed.tech/topics/process.md>), [Unix](<https://devfeed.tech/topics/unix.md>), [Terminal](<https://devfeed.tech/topics/terminal.md>), [systems](<https://devfeed.tech/topics/systems.md>)

Tags: [id](<https://devfeed.tech/tags/id.md>), [operating-systems](<https://devfeed.tech/tags/operating-systems.md>), [process](<https://devfeed.tech/tags/process.md>), [systems](<https://devfeed.tech/tags/systems.md>), [terminal](<https://devfeed.tech/tags/terminal.md>), [unix](<https://devfeed.tech/tags/unix.md>)

## AI overview

The article explains how reptyr moves a running process from one terminal to another by attaching with ptrace, opening the new terminal, and redirecting standard output and error. It also describes UNIX controlling terminals, sessions, process groups, and restrictions involving ioctl and setsid().

## Source excerpt

reptyr (announced recently on this blog) takes a process that is currently running in one terminal, and transplants it to a new terminal. reptyr comes from a proud family of similar hacks, and works in the same basic way: We use ptrace(2) to attach to a target process and force it to execute code of our own choosing, in order to open the new terminal, and dup2(2) it over stdout and stderr.