chmod. $@ - , . lock . , , , . UNIX , - .  * 7. *  termcap c mntf mntlook umntsys , lrgf ,    . - , , . 'c' . - mntf, mntlook umntsys - - . , lrgf . UNIX , , - , UNIX. - (CPU), , - , . - , , , , - : , , . , , UNIX, , . ( UNIX) (kernel). - . . , . - . - , UNIX . , , , "" . , UNIX , - , . - , , , , . . 7-1 UNIX. , - . , - . , , - . . 7-1 UNIX -------------------------------------------------------------- +-----------+ | | +------------+ | | | | | | +------------+ +-----------+ /dev/lp0 lpn /dev/rmt0 .../dev/rmtn \ | | / \ | | / \ | | / \ \ | | | | / / +-------------------+------- /dev/fd0 fd:1,2 | +-------------+ |--- +-----------+ /dev/tty00----| | | | | | +--------+ -- | | | |--- +-----------+ | | / | +-------------+ |-------- fdn | | +-------------------+ +--------+ / / | | | \ \ +--------+ / | \ |.| ttynn /dev/hd01 hdnn +--------+ +----------+ fd:0 | | | | | | | | +----------+ -------------------------------------------------------------- UNIX " ". : . . (, /dev/hd0) . (, /dev/tty00 /dev/rfd0) , . , - , . , - . 'c' , , . (termcap), . - . , . . , UNIX - , , . . lrgf . mntf - . , mntlook - , .   . , , - . - , . , , stty(1) ioctl(2). termio(7) - . / , . . - , . -, - , , /- . - "" . - , - . - - , - . . 7-2. : - , - - . , - . . 7-2. ------------------------------------------------------------------- +-------+ : : | | : +--------+ +--------+ +-------+ : dzrint() |-------| : ttread() |.| canon()|.| ttin()|.| : +-----+ | | : /---| |<-------| |<------| |<--|dbuf | | | : / +--------+ +--------+ / +-------+ : | | | +----+| : / / : +-----+ | |ubuf||<---/ clist clist / ccblock : | +----+| : / : | +----+| : +--------- / ttxput() : | |ubuf||---- | : | +----+| : \ +-------+ <--+ +--------+ : +-----+ |-------| : \ |.| | | : |dbuf | | | : \--->||------->||------------------->| | | | : +-------+ ttout()+--------+ dzxint() : +-----+ +-------+ : ttwrite() : clist ccblock /|\ | ------+ ------------------------------------------------------------------- - , - , dbuf. , . ttin(), clist, - . ( "" , .) - , -- . canon() - . ("" , - , .) , - . ttread(), - . , : - . - , - . ttwrite(), - ttout(). - - dzxint().   , , - . , UNIX . od - (octal dump). , . , od , . od - , od - , . , $ od -cx test string ^d ^d : ------------------------------- | | 0000000 6574 7473 7320 7274 6e69 0a67 | t e s t s t r i n g \n | 0000014 | $ | od - - . -cx , - ASCII, 16- - . , - , , od . , CTRL-D. CTRL-D od , , - ASCII. , , - , , . , 6574 - , t e, 65 - ASCII e, 74 - ASCII- t. od, CTRL-D . , . od . , - . , , CTRL-D . - od. . . System V - "stty -a", Berkeley "stty everything". System V , Berkeley. ( UNIX' - : System V - AT&T Bell Laboratories, Unix System Laboratories; BSD (Berkeley Software Distribution) - ; XENIX - Microsoft.- . .) XENIX: -------------------------- | | speed 9600 baud; line = 0; | intr = DEL; quit = ^|; erase = ^h; | kill = ^u; eof = ^d; eol = ^` | parenb -parodd cs7 -cstobp hupcl cread -clocal | -ignbrk brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl -iuclc | ixon ixany -ixoff | isig icanon -xcase echo echoe echok -echonl -noflsh | opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel ff1 | , , , "icanon". , , , ( ). ? (backspace) . CTRL-H, CTRL-H. canon() CTRL-H, : " CTRL-H , , ." - . , CTRL-H . , : ---------------------------- | | $ stty -icanon | $ od -cx | test string^h^h^h^h^h^hcase | ^d... | | 0000000 6574 7473 7320 7274 6e69 0867 0808 0808 | t e s t s t r i n g \b \b \b \b \b | 0000020 6308 7361 0a65 0a04 0a0a 0a0a 0a0a 0a0a | \b c a s e \n 004 \n \n \n \n \n \n \n \n \n | "string" 08, ASCII- CTRL-H. 08 , - CTRL-H "- " . CTRL-H , od . : - , (EOF). CTRL-D, . od, . CTRL-D - 004 case \n. , Berkeley "" ("cooked") "" ("raw") stty, , "canon" "-canon" System V.   , stty -a "intr" "quit". , . intr quit , . - stty. "intr" , . . : $ stty intr x $ this is a junk stringx $ x , . , - . "delete", : $ stty intr DEL ? , stty , , , - . , - : while : do : done . -- , DEL, . , . , . "eof". (end of file), CTRL-D. , - UNIX CTRL-D. CTRL-D shell, : "Shell, ". , CTRL-D , shell, - " , EOF", , init. init getty , "login:" . , - shell CTRL-D. , . : $ stty eof x $ x login: x. x, CTRL-D, . , , - , UNIX .   /dev. , , tty01. /dev/tty01. - tty UNIX, , . , , , "ls -l" , , - . cdevsw[], - , - . . , . XENIX: ---------------------------- | | crw--w--w- 1 russ tricks 0, 0 Jun 22 02:34 /dev/console | crw--w--w- 1 russ tricks 0, 1 Jun 22 00:41 /dev/tty02 | crw--w--w- 1 root tricks 0, 2 Jun 21 17:56 /dev/tty03 | crw--w--w- 1 root tricks 0, 3 Jun 21 05:47 /dev/tty04 | crw-rw-rw- 1 root root 0, 4 Feb 18 17:09 /dev/tty05 | crw-rw-rw- 1 root root 0, 5 Feb 18 17:09 /dev/tty06 | crw-rw-rw- 2 root root 5, 0 Jun 21 20:23 /dev/tty11 | crw--w--w- 2 root tricks 5, 8 Jun 22 02:20 /dev/tty12 | crw-rw-rw- 2 root root 5,128 Feb 18 17:09 /dev/tty13 | crw-rw-rw- 2 root root 5,136 Feb 18 17:09 /dev/tty14 | 'c' , - , , - . (0 5) . , ( ). , "", "- " . , /dev/tty , , . - /dev/tty . - tty tty01 , . - , /dev/tty.   , - , . . - ( rw--w--w-), , , , . , "chmod 600 `tty`", - tty . UNIX' mesg. "mesg n" . - - . , 9. , , ( , ), . - ioctl. . , ioctl , , , , ! , - , , . write(1). , "". . , "mesg n", write - . " ", - , . - : $ while : > do > clear > /dev/tty00 > done & ( - kill ), - tty00 . - - , . , . , . , , (root), , . ! , - - - write, . write - , . . , , - .   , , - , , . , ( ) (long) . . - activ , , - . - , .   , - , .. . , , , . , - . - vi. - , .., vi, , , . ? UNIX, . - . , - . , shell, stty, - . - , - . 1 #include 3 struct termio tsav, tchg; 5 main (argc, argv) 6 { 7 int c; 9 if (ioctl (0, TCGETA, &tsav) == -1) { 10 perror("can't get original settings"); 11 exit(1); 12 } 14 tchg = tsav; 16 tchg.c_lflag &= ~(ICANON | ECHO); 17 tchg.c_cc[VMIN] = 1; 18 tchg.c_cc[VTIME] = 0; 20 if (ioctl (0, TCSETA, &tchg) == -1) { 21 perror("can't initiate new settings"); 22 } 24 while (1) 25 { 26 c = getchar(); 28 if (c == 'x') 29 break; 31 putchar(c); 32 } 34 if (ioctl(0, TCSETA, &tsav) == -1) { 35 perror("can't reset original settings"); 36 exit(3); 37 } 38 } "" , , - , . ioctl . ( 14). - 16-18. 16 - . 17 , - . 18 , 0. , . - 20. . while - , . x - , , . , . , , . , . ? : " UNIX?". - . : " . - , - . , . , , ." , , - , , - . . , . , - , , , .. , , stty. , . , , - , ioctl. , , - . , - . : 1 #include 2 #include 4 struct termio tsav, tchg; 6 main (argc, argv) 7 { 8 int c; 10 /* change the terminal based on file primitives */ 11 close(0); 12 if (open("/dev/tty",O_RDWR|O_NDELAY) == -1) { 13 perror("can't open tty"); tty 14 exit(1); 15 } 17 /* change the terminal based on line disciplines */ 18 if (ioctl (0, TCGETA, &tsav) == -1) { 19 perror("can't get original settings"); 20 exit(2); 21 } 23 tchg = tsav; 25 tchg.c_lflag &= ~(ICANON | ECHO); 26 tchg.c_cc[VMIN] = 1; 27 tchg.c_cc[VTIME] = 0; 29 if (ioctl (0, TCSETA, &tchg) == -1) { 30 perror(can't initiate new settings"); 31 } 33 while (1) 34 { 35 putchar('.'); 36 c = getchar(); 38 if (c == 'x') 39 break; 41 putchar(c); 42 } 44 if (ioctl(0, TCSETA, &tsav) == -1) { 45 perror("can't reset original settings"); 46 exit(3); 47 } 48 } 11-15. ( ) . /dev/tty. , - . , , NODELAY. , - (.. ), , -, . 35 . , , . , . , - . , , .   , - , . - , . , - , , vi. termcap (terminal capabilities - - ), . termcap. /etc/termcap. termcap vi Berkeley. , System V. System V Release 3 termcap , terminfo AT&T. terminfo today 5, terminfo . Berkeley termcap - - , . termcap, , . , , . , , . termcap - Apple II. , Videx UltraTerm Apple II+. , , termcap, - , - . , Apple , termcap, . , termcap, - . , , termcap. , , Apple, ("scroll reverse"). , termcap . () , . , , termcap - , Apple vt52. termcap , - . termcap: a2|aii|Apple II with UltraTerm :\ :bl=^G:\ :bs:\ :cd=^K:\ :ce=^]:\ :cl=^L:\ :cm=^^%r%+ %+ :\ :co#80:\ :cr=^M:\ :do=^J:\ :ho=^Y:\ :kb=^H:\ :kd=^J:\ :kl=^H:\ :kr=^\\:\ :ku=^_:\ :le=^H:\ :li#24:\ :nd=^\\:\ :nl=^J:\ :se=^O:\ :so=^N:\ :up=^_: . 7-1 termcap - Apple vt52. - , "". 7-1 ------------------------------------------------------------- Apple II vt52 ------------------------------------------------------------- bl - ^G ^G (bell) bs - ^H (can backspace with ^H) cd - ^K \EJ (clear to end of display) ce - ^] \EK (clear to end of line) cl - ^L \EH\EJ (clear entire screen) cm - ^^%r%+ %+ \EY%+ %+ (cursor motion) co - #80 #80 (number of columns in a line) cr - ^M ^M (carriage return) do - ^J ^J (down one line) ho - ( cm) ^Y \EH (home cursor) kb - backspace ^H ^H (sent by backspace key) kd - " " ^J \EB (sent by down arrow key) kl - " " ^H \ED (sent by left arrow key) kr - " " ^\\ \EC (sent by right arrow key) ku - " " ^_ \EA (sent by up arrow key) le - ^H ^H (cursor left) li -