sarima@gryphon.COM (Stan Friesen) (03/03/89)
For those of you who requested it here is a brief sumary of the data I got about pty's (pseudo-terminals). First, a very basic overview. Pseudo-tty's are an interprocess communication mechanism that simulates regular external tty's. They are implemented as a series of *pairs* of devices, a master and a slave. The slave devices are usually named something like '/dev/ttypXX', and the master devices always have a corresponding name with a different prefix. On many systems the master is called something like '/dev/ptyXX', but on our system it is called something like '/dev/vtXX'. The two devices in each pair are connected output to input, both directions. Thus output on the slave becomes input on the master and vice-versa. The value of these devices is in the fact that the slaves act *exactly* like a standard tty device as far as the programming using them is concerned. Thus all ioctl() calls have the expected effect, and all canonical I/O processing is performed. In our implementation output on the master is even echoed back to its input. Thus the master is a sort of virtual peripheral. The Carrier Detect condition in the slave is tied to the master being opened by some process. Thus, an attempt to open a slave for which the master is not open will hang pending an open of the master, unless O_NDELAY is set, in which case it will return failure. In order to keep things from getting out of hand, only one open is permitted of the master, so that there is always exactly one controlling process. Thus, the standard method for allocating a pseudo-terminal is to loop through the name space for the masters until an open() succeeds. Then the the name of the corresponding slave is derived and passed to the program needing it. This is often accomplished by fork()ing a sub-process to open the slave and redirect standard input and output before running the program that requires a "real" tty device. I have been told, and I seem to remember, that there are several special ioctl() calls that are available to the master. Unfortunately, I do not remember, and was not told, what they actually are and do. -- Sarima Cardolandion sarima@gryphon.CTS.COM aka Stanley Friesen rutgers!marque!gryphon!sarima Sherman Oaks, CA