UNIX mAn pAges:pty(7)

来源:互联网 发布:分水岭分割算法 博客 编辑:程序博客网 时间:2024/04/30 02:15
PTY(7M) PTY(7M)NAME pty, pts -pseudo terminaldriverDESCRIPTION The pty driver provides a device-pair termed a pseudo terminal. Apseudo terminal is a pairof character devices, amaster device and a slave device. The slavedevice providesprocesses an interface identical to that described in termio(7). However, whereas allother devices which provide the interface described intermio(7) have a hardware device of some sort behind them, theslave device has, instead, another process manipulating it through the masterhalf ofthe pseudo terminal. That is, anything written on the master device is given to the slave deviceas input and anythingwrittenon the slave device is presented as input on the masterdevice. The following ioctl calls apply only to pseudo terminals: TIOCPKT Enable/disable packetmode. Packet mode is enabled by specifying (by reference) a nonzero parameter and disabled by specifying(by reference) a zero parameter.When applied tothe master sideof a pseudo terminal, eachsubsequent readfrom the terminal will return data written on the slave part of thepseudo terminalpreceded by a zero byte (symbolically defined as TIOCPKT_DATA), or a singlebyte reflecting control status information. In the lattercase, the byte is aninclusive-or ofzero ormore ofthe bits: TIOCPKT_FLUSHREAD wheneverthe read queue for the terminalis flushed. TIOCPKT_FLUSHWRITE wheneverthe write queuefor theterminal is flushed. TIOCPKT_STOP wheneveroutput to the terminal is stopped a la ^S. TIOCPKT_START wheneveroutput to the terminal is restarted. TIOCPKT_DOSTOP whenevert_stopcis ^S and t_startc is ^Q. TIOCPKT_NOSTOP wheneverthe start and stop characters are not ^S/^Q. This mode is used by rlogin(1C) and rlogind(1M) to implement a remote-echoed, locally ^S/^Q flow-controlled remote login with proper back-flushing of output; it can be used by other similar programs.Page 1PTY(7M) PTY(7M)ALLOCATION The code sequence shown below demonstrateshow to allocatepseudo terminals. Pseudoterminals, likeall files, musthave the correct file permissions to be accessible. The__getpty(3) library function takes care ofthis problem. #include #include /* *Find a pseudo tty to use and open both sides. * filedes[0] receives the masterfile descriptorwhile filedes[1] * receives the slave. The master is opened withO_NDELAY as commonly * neededin daemons suchas rlogind and telnetd. */ int /* -1 on failure */ findPseudoTTY(int *filedes) { char *line; line =_getpty(&filedes[0], O_RDWR|O_NDELAY, 0600, 0); if (0 == line) return -1; if (0 > (filedes[1] = open(line, O_RDWR))) { (void)close(filedes[0]); return -1; } return0; }FILES /dev/ptc - master pseudo terminal /dev/tty[qrstuvwxyz][0-99] - slave pseudo terminals /dev/pts - equivalentto /dev/ttyq[0-9]SEE ALSO getpty(3)
原创粉丝点击