13.  - , , . , , - , . , , , , . , , uucp, - , , - , . , , , , , - , . - UNIX , , . , , open read , . 13.1. , , , , . , : , . , , , . - , . - , +-----------------------------+ +-----------------------------+ | +------------+ | | +------------+ | | | | | | | | | | +-----+------+ | | +-----+------+ | | ----+-------+------+------- | | ----+-------+------+------- | | +---+----+ +-------+------+ | | +---+----+ +-------+------+ | | | | | | | | | | | | | | | | | | | | | | | | | | +--------+ +--------------+ +-++-+ +--------+ +--------------+ | +-----------------------------+ ++ +-----------------------------+ | +-------------+---------------+ | +------------+ | | | | | | +-----+------+ | | ----+-------+------+------- | | +---+----+ +-------+------+ | | | | | | | | | | | | | | +--------+ +--------------+ | +-----------------------------+ 13.1. 381 - . , , - : * , , ( ) - . - . UNIX. ; - , , , - . * "Newcastle", - ( "The Newcastle Connection" - . [Brownbridge 82]). ( ), , - . - , , , , . * "" , , , - ; . , - , , . ; - , - , . - , , , , - - , , . , , Newcastle "" , ; , , - , , - . 13.1  13.2. - - . , , . - . , - ; , . , - , , , - . 382 - . -, (. [Birrell 84]); , , , , - - . - . , 11: - , . - . 13.4 - -, . +-----------------------------+ +-----------------------------+ | +------------+ | | +------------+ | | | | | | | | | | +-----+------+ | | +-----+------+ | | ----+-------+------+------- | | ----+-------+-------------- | | +---+----+ +-------+------+ | | +---+----+ | | | | | | | | | | | | | | | | | | | | | | +--------+ +--------------+ +-++-+ +--------+ | +-----------------------------+ ++ +-----------------------------+ | +-------------+---------------+ | +------------+ | | | | | | +-----+------+ | | ----+-------+-------------- | | +---+----+ | | | | | | | | | | +--------+ | +-----------------------------+ 13.2. , - , -. , , sbrk. , - , , , , - ( 13.3). , , - - , (, ), . (, , write). - ; , , , - . , , 383 +----------------+----------+---------------+--------------------+ | | | | | | -| | -|------- ------| | | | | | +----------------+----------+---------------+--------------------+ +------------+-----------+---------+---------------------+ | | | | | | | | |---- ---| | | | | | | | | | | +------------+-----------+---------+---------------------+ 13.3. ( ), - , , , , . , , - . ; - . , , , : getppid, open, write, fork, exit signal. getppid , , . , , , getppid, . - , , . , - . - , , getppid. (, - -) , - . open, - , . - - , - . - . , ; open - , -. 13.4. write, - , write, . - -. - , - ( - ); . 384 +--------------------------------------+ +---------------------+ | | | | | - | | | | - | | | | | | | | - | | | | | | | | +--------+| | +---------+ | | +-----+ +-----+ +-----+ |-|----------| | | | | | | | | | | || | +---------+ | | +-----+ +-----+ +-----+ +-+------+| | | | | -+-+ | | ++- -+---+ | | | | +-----+ | +-----+ |+-----+ - | | | | | | +-+- -+-+| | | | | | +-----+ +-----+ +-----+ | | | | | | | | | | | | +-----+ +-----+ | | | | | | | | | | | | +-----+ +-----+ | | | +--------------------------------------+ +---------------------+ 13.4. open - , , . read ; - ( , ). , - , - . , - , fork. , -, , . , , fork - , . - , fork, - , , - - . - ( ) , - fork; -, , - fork. - fork; - . - ( ) - . 13.5: "-", - . fork , - , . - 385 +----------------------+ +----------------------+ | +------------------+ | | +------------------+ | | | - |-------------| - | | | +---------+--------+ | | +------------------+ | | | | | | | | | | | | +---------+--------+ | | +------------------+ | | | -|-------------| - | | | | | | | | | | | +------------------+ | | +------------------+ | +----------------------+ +----------------------+ 13.5. fork : - - , . . , - - fork, , - , , . , , - , - , , - . fork 13.6. , - . - - . +-------------------------------------------------------+ | +------------------+ +-----------------+ | | | - +----------+ - | | | +------------------+ +-----------------+ | | - - | +-------------------------------------------------------+ - - +---------------------------+ +---------------------------+ | - | | - | | +-----------------------+ | | +----------------------+ | | | | | | | | | | +-----------------------+ | | +----------------------+ | +---------------------------+ +---------------------------+ 13.6. fork , - : , , , , - - , , . - , , - . - 386 , - . , exit: -, , , . signal, - , , . - , . - ( 13.7): - , signal - , +------------------------------------------------------------+ | sighandle /* */ | | : | | : | | { | | ( - | | ) | | { | | ( ) | | ; | | ( | | ) | | -; | | | | -| | ; | | } | | /* */ | | { | | /* | | * | | */ | | -; | | } | | } | | | | satellite_end_of_syscall /* - | | * , - | | * | | * */ | | : | | : | | { | | ( | | ) | | - | | , ; | | /* | | * */ | | : , - | | ; | | } | +------------------------------------------------------------+ 13.7. 387 - . . , , - . , - , - . . 1. - - , , - , - , . 2. , , longjmp. , - , . 3. - ( longjmp), - . - - . , - : , , - , . - +------------------------------------------------------------ | read - | - | - - | - | - | - - | - read | - - | - | - | - | - | - - | - - | - ( | - "break") | - | - | - | - | - - | - : | - | - | | v 13.8. 388 , , , , - ( 13.8). (break), - - . - , read. , . , - , . read - , , - -, . - exit, - -. , - read . , stat, ( stat , - ). . - . - , - , - . - , . , - ( ). , . read, , - , - . - : - , , ; - . , , , . , , , . - , . - , , . - , kill - -, . - , , - , ( - ) . 389 13.2 NEWCASTL , - - () . , - , , - . , - , , , . , , ( ), . . : , , - , - , . , , "sftig!/fs1/mjb/rje" "/fs1/mjb/rje", "sftig". , - uucp UNIX. - , : /../sftig/fs1/mjb/rje "/../" - , , ; . - - - +-----------------------------+ +----------------------------+ | | | - | | - | | | | | | (- | | +------+ | | | | | | +--------------+--- | | | ) | | | | | +------+ | | | | | | | | | | | +-------------+ | | | | +------+ | | | | | | | +----+--- | | | | | | | | | +------+ | | | | | | | | | | | | | | | | | | +------+ | | | | | | | +-----+ | | | | | +----+---------------+--------+ +----+-----------------+-----+ | | | | +----+---------------+--------+ +----+-----------------+-----+ | | | | | | | | | | | | | | | | +--------------------+--------+ +----------------------+-----+ | | +-------------------------------------+ 13.9. () 390 UNIX, - , (. [Pike 85]). , Newcastle, - ; -, - . , - - . , - . 13.9 , - . , - . : open("/../sftig/fs1/mjb/rje/file",O_RDONLY); open - - , "sftig". , - , , - , - , . , - , - , -. , - , . , "mjb" , - . , , - "mjb" . , , , . , - - . - . , -- , . , , , . mkdir (. 7), . , - . mkdir