Creating a PTY
In this recipe, we'll create a PTY using a C program. A PTY consists of two parts: a master (referred to as a pseudo-terminal master, or PTM) and a slave, or PTS. The program will create a PTY and print the path to the slave on the current terminal. We can then connect to that PTS with an application called
screen and type away, and the characters will be printed to both the master and the slave. The slave is where the
screen program is connected to, which is our terminal in this case. The master is usually quiet and runs in the background, but for demonstration purposes, we'll print the characters on the master as well.
Knowing how to create a PTY enables you to write your own terminal applications, such as
xterm, Gnome Terminal,
tmux, and so on.
For this recipe, you'll need the GCC compiler, the Make tool, and the
screen program. Installation instructions for
screen are found in the Technical requirements section of this chapter...