Today I learned how pseudo-terminal, pseudo-tty, or PTY works by reading The TTY demystified.

In short, pseudo-terminal is used for running and interacting with programs. A pseudo-terminal consists of a master and slave device. The slave device emulates a terminal device and connects with master device. Master device provides means for a terminal emulator process to control the slave devices. Terminal multiplexers, such as tmux, create multiple pseudo-terminals to interact with multiple running programs.

The file descriptor of master device can be created by calling posix_openpt. The file path to slave device can be found by calling ptsname.