Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Bit by bit, we’ll work toward the development of a function, ptyFork(), that does most of the work to create the setup shown in Figure 64-2. We’ll then use this function to implement the script(1) program. Before doing this though, we look at the various library functions used with UNIX 98 pseudoterminals:
The posix_openpt() function opens an unused pseudoterminal master device, returning a file descriptor that is used to refer to the device in later calls.
The grantpt() function changes the ownership and permissions of the slave device corresponding to a pseudoterminal master device.
The unlockpt() function unlocks the slave device corresponding to a pseudoterminal master device, so that the slave device can be opened.
The ptsname() function returns the name of the slave device corresponding to a pseudoterminal master device. The slave device can then be opened using open().