10. - - , - , , , , - , , - . - : - , - - . , - - , , - , - . . , , - . , : - , , . " ", . , , - , . ps - , . : - , . , , - 8, : , - , . - -, . - . - . 10.1  UNIX - - -. 2, - , , ; - , . - - - -. - (. 2.1). , , . - . , , "", " ", - 290 , . , , : - - -. , open, close, read write, , . ioctl - -, (*). , - . , , , . 10.1.1  , . - , - , , . - , , - "". , , - . , - . -, , . - , , . -, - , ; . , , - . - . - , - , . " - " - - - ( 10.1). , . open close, , "" . mount umount , - . read write, - - , , - . . - . " - " - - - - : , - , , - ---------------------------------------- (*) , fcntl - , , - . ioctl . 291 . , " ", ( 8) - , " " . , . mknod, ( ), . mknod , . , mknod /dev/tty13 c 2 13 "/dev/tty13" - , "c" , - "- " ("b", , ), "2" - - , "13" - . - , , - . "/dev/dsk1" 0, gdopen 0 - ( 10.2); - "/dev/mem" 3, +------------------------------------------------------------+ | open close | | open close read write ioctl read write | | mount umount | +--+-----+----+-----+-----+------------+-----+-----+-----+---+ | | | | | | | +-+-----+---+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----+-----+ +--+-----+----+-----+-----+-+ ++-----+---------+-----+ | | | - | | -| | - | | | | | +--+-----+----+-----+-----+-+ +--+------+--------+---+ +--+-----+----+-----+-----+-+ +--+------+--------+---+ |open close read write ioctl| | open close strategy| | | | | | | | | | | - | | | - | | | | | | | +------------+--------------+ +-----------+----------+ +--------+----------+ +---------+---------+ | | | | +--------+----------+ +---------+---------+ +-------------------+----------------+ | 10.1. 292 mmread 3 - -. nulldev - "" , - , . ; . - ; , , , - . 10.1.2  - . , , , , - , +-----------------------------------------------+ | - | +-------+--------+---------+--------------------+ | | open | close | strategy | +-------+--------+---------+--------------------+ | 0 | gdopen | gdclose | gdstrategy | +-------+--------+---------+--------------------+ | 1 | gtopen | gtclose | gtstrategy | +-------+--------+---------+--------------------+ +----------------------------------------------------------------+ | - | +------+-----------+-----------+---------+-----------+-----------+ | | open | close | read | write | ioctl | +------+-----------+-----------+---------+-----------+-----------+ | 0 | conopen | conclose | conread | conwrite | conioctl | +------+-----------+-----------+---------+-----------+-----------+ | 1 | dzbopen | dzbclose | dzbread | dzbwrite | dzbioctl | +------+-----------+-----------+---------+-----------+-----------+ | 2 | syopen | nulldev | syread | sywrite | syioctl | +------+-----------+-----------+---------+-----------+-----------+ | 3 | nulldev | nulldev | mmread | mmwrite | nodev | +------+-----------+-----------+---------+-----------+-----------+ | 4 | gdopen | gdclose | gdread | gdwrite | nodev | +------+-----------+-----------+---------+-----------+-----------+ | 5 | gtopen | gtclose | gtread | gtwrite | nodev | +------+-----------+-----------+---------+-----------+-----------+ 10.2. - , , - . - , - , . , - , . , - , - 293 , . , , (, stat), , . . , ; - , (- , ). - . +------------------------------------------------------------+ | open /* */ | | : | | | | : | | { | | , -| | ; | | | | , ; | | | | ; | | | | ( setjmp) | | ; | | | | ( ) | | { | | -| | - - | | ; | | -| | : , -| | ; | | } | | | | { | | -| | -| | -; | | -| | : , -| | ; | | } | | | | ( ) | | , | | ; | | } | +------------------------------------------------------------+ 10.3. 10.1.2.1 Ope , - 294 (. 5.1), , - . , - , - , . - , , , open ( 10.3). - - open, - - , - - open, . , , open, - , : , . open - . , open - , () , . - (, ). " ", , open . - , , , - , - . , , getty, "" ( 7.9), - , - , . open : , , , . , setjmp ( 6.4.4), - open; , - , , longjmp ( 6.4.4), - open . , . - , , , , - . open . , . - "no delay" ( ), , open, . open , . "no delay", , - read, ( 10.3.4). , - , , - 5, open open. , - , "", open, . - 295 , "" - , . "" , - . , - : - ; (**). +------------------------------------------------------------+ | close /* */ | | : | | : | | { | | ( 5); | | ( 0) | | finish; | | ( , -| | | | ) | | finish; /* */ | | ( ) | | { | | | | -- | | ; | | , - | | - | | ; | | } | | ( ) | | { | | ( ) | | finish; | | -| | ; | | | | - ; | | , - | | - | | ; | | , -| | ; | | } | | finish: | | ; | | } | +------------------------------------------------------------+ 10.4. ---------------------------------------- (**) , , - . 296 10.1.2.2 Clos , . , close - close , - , , ; - , , , - . - open, , , - . , - : close - , , , open close - . ( 10.4). , , , - , . 1. , , , . , close , , - , . - , - . , ls -l , - ("c" ) - , (9 1) . , 1, , . crw--w--w- 1 root vis 9, 1 Aug 6 1984 /dev/tty01 crw--w--w- 1 root unix 9, 1 May 3 15:02 /dev/tty01 , - . 2. , - . , , . , - , close - . , - , - , - " ". - . , , - . 3. . , - , 297 . 10.1.2.3 Read Writ - . -, read write, . - , , . , - ( 10.3.1). "", - write "" . , , (.. ): , , - , . , - , | | +-----+ 160110| CSR | +------+ +---------tty00 | RDB +---------+ dz00 +-+---------tty01 | TDB | +------+ | ... +-----+ +---------tty07 160120| CSR | +------+ +---------tty08 160122| RDB +---------+ dz01 +-+---------tty09 160126| TDB | +------+ | ... +-----+ +---------tty15 | | 10.5. - - VAX DZ11 , - . - . -- , , - , - , . , . , - VAX-11 - ( ) - ( ), . , VAX DZ11 8 (. [Levy 80], VAX). (CSR) DZ11 160120, - (TDB) - 120126, (RDB) - 160122 ( 10.5). , "/dev/tty09", (1 = 9 8) 298 . . DZ11 "" - , . " " , DZ11 - , . DZ11 . -, , . - , . , IBM 370 "Start I/O" ( -), - -, . . - -, . , - - () . - , - . , - . - , . - , - , , , , - , . , "", , . 10.1.2.4  - , , , - strategy ( ) - . strategy -, , . . - ; (- ) , . , 9. ; , ( ). , - ( , - ) . , . - . , , - , 3. - 299 , (, bread bwrite), , - . , - . , - - (, ), , . 10.1.2.5 Ioctl ioctl stty ( ) gtty ( - ), UNIX. - , , , . , ioctl - . , ioctl, , , -. , . ioctl 10.3.3. , : ioctl(fd,command,arg); fd - , open, command - (), , arg - ( ). - ; , , , , , - . arg - - . , - , ioctl, - , , , , , - . 10.1.2.6 ,  , stat chmod, , , ; , . lseek . , - lseek, ,