Advanced Programming in the
UNIX Environment

by W. Richard Stevens
Addison-Wesley Professional Computing Series
0-201-56317-7 * Hardcover * 768 pages * ©1992
[Buy this book]

Chapter 19. Pseudo Terminals

Introduction * Overview * Opening Pseudo-Terminal Devices * System V Release 4 * 4.3+BSD * pty_fork Function * pty Program * Using the pty Program * Advanced Features * Summary

Example Relevant Functions
19.1 ptym_open, ptys_open
pseudo tty open routines
master/slave. SVR4 version
strcpy, open, close,
grantpt, unlockpt, ptsname,
19.2 ptym_open, ptys_open
pseudo tty open routines
master/slave. 4.3BSD/SunOs version.
strcpy, open, close,
chown, chmod
19.3 pty_fork
Combines the open of the master+slave pty
with a call to fork, establishing the child
as a session leader with a controlling terminal.
Works under both SVR4 and 4.3BSD/SunOs.
err_sys (Stevens' lib),
ptym_open, ptys_open,
fork, setsid, close, ioctl,
strcpy, tcsetattr, dup2
19.4 The pty program
Run an arbitrary program under a pty.
The program "thinks" it is running connected
to a terminal.
Usage:   pty prog args...
isatty, tcgetattr, tcsetattr,
getopt, optarg, optind, opterr,
err_quit (Stevens' lib),
err_sys (Stevens' lib),
pty_fork (Stevens' func),
tty_raw (Stevens' lib),
ioctl, execvp, fprintf,
atexit, exit,
do_driver (Stevens' func),
loop (Stevens' func)
19.5 loop
main loop of pty program
Copy stdin to the pty master and
data received from pty master to stdout
fork, getpid, kill, exit,
err_sys (Stevens' lib),
read, writen (Stevens' lib),
signal_intr (Stevens' lib)
19.6 do_driver
Connect a driver program to the pty program
to drive the process under the pty with some
logic (e.g. like expect). Used with
     pty -d driverprog program args...
s_pipe, err_sys (Stevens' lib),
fork, close, dup2, execlp,

[Buy this book]