9.  , , - . , - ; , . , - - , . , , 8 , 1 - . ( ), , , - , . , , . - . UNIX - , , - . (). PDP-11, - 64 . - , . BSD ( 4.0) , " " (demand paging), - , ; - V UNIX. , - , . - , : - . - "" . - . 9.1  : - , . 9.1.1  , - . , 253 . , , ; , , - , . , , , . , - , , - . - , - , , , . , , , , . , , , , - , " ". , - , (, - ), ( - ) . ; . , . , , - - . - , 10000 , 1, - 9.1. , , , - . 9.2 (malloc). , - , . , , ( ). , . 9.3 , 100, 50 100 . , , 250 , 9750 , 251. +------------------------------------+ | 1 10000 | +------------------------------------+ 9.1. 254 +------------------------------------------------------------+ | malloc /* -| | */ | | : (1) /* - | | */ | | (2) | | : - | | 0 - | | { | | ( ) | | { | | ( | | ) | | { | | ( == ) | | ; | | | | ; | | ( ); | | } | | } | | (0); | | } | +------------------------------------------------------------+ 9.2. , . : +------------------------------+ +------------------------------+ | 1 10000 | | 101 9900 | +------------------------------+ +------------------------------+ () () +------------------------------+ +------------------------------+ | 151 9850 | | 251 9750 | +------------------------------+ +------------------------------+ () () 9.3. 1. . - , , - . . 2. . , , ( ), . . 3. , 255 - . - . , , 50 , 101, , , . 100 , 1, , - , . - 9.4. , 200 () . - 150 , (. 9.5). , , - 350 +------------------------------+ +------------------------------+ | 251 9750 | | 101 50 | +------------------------------+ +------------------------------+ | 251 9750 | () +------------------------------+ () +------------------------------+ | 1 150 | +------------------------------+ | 251 9750 | +------------------------------+ () 9.4. +------------------------------+ +------------------------------+ | 1 150 | | 1 150 | +------------------------------+ +------------------------------+ | 251 9750 | | 451 9550 | +------------------------------+ +------------------------------+ () () 9.5. , , 151. , 350 - , , . , - - , , - . UNIX - , V - 256 . "- " , - . . , ; , - . 9.1.2  , , : 1. fork, -. 2. brk, - . 3. . 4. - . fork , , , (), . , - , , - , , 0. ( 1-3), (. 9.12) , . - . -, , - . , . , - , , . - , , - , . , , -. , , () -- . . , - , . , - . , , - . 9.6 (*). - : , . 257 --------------------------------------- (*) , , . , +----------------------+ +-----------------+ | 0 278 ----+-------684--+---> | +----------------------+ +-----------------+ | 1 432 ----+------------+---> | +----------------------+ +-----------------+ | | +--------+---> | +----------------------+ - +-----------------+ | - | -+-------+---> | | - | -- +-----------------+ | - | --+------+---> | +----------------------+ --- +-----------------+ | 64 573 ----+---+-- +----+---> | +----------------------+ -- - +-----------------+ | 65 647 ----+----+- 690 | | +----------------------+ - - +-----------------+ | 66 595 ----+-----+ - +----------------------+ - | | - +----------------------+ - | - | - | - | - +----------------------+ - |128 401 ----+-------+ +----------------------+ | | +----------------------+ 9.6. 2, 64, - 62 . , 0, 1, 64, 65, 66 128; 62 , 61 , - . , , 62, - . 9.7. 9.6 9.7 , , , ; , - , - . , , , , - . , 258 , +----------------------+ +-----------------+ | 0 401 <---+-------684--+---- | +----------------------+ +-----------------+ | 1 370 <---+------------+---- | +----------------------+ +-----------------+ | | +--------+---- | +----------------------+ - +-----------------+ | - | -+-------+---- | | - | -- +-----------------+ | - | --+------+---- | +----------------------+ --- +-----------------+ | 64 788 <---+---+-- +----+---- | +----------------------+ -- - +-----------------+ | 65 492 <---+----+- 690 | | +----------------------+ - - +-----------------+ | 66 647 <---+-----+ - +----------------------+ - | | - +----------------------+ - | - | - | - | - +----------------------+ - |128 955 <---+-------+ +----------------------+ | | +----------------------+ 9.7. , ( ) . , (. 9.4). 9.1.2.1 fork fork ( 7.1) , - - , . , , , () - . , - - ; - " " (. 6.1) . - " - ", , ; - fork . 9.1.2.2  , , brk, , - . 259 , , +------------+ +------------+ +---------+ | 0 278 | | 0 278 -+-----684--+---> | +------------+ +------------+ +---------+ | 1 432 | | 1 432 -+----------+---> | +------------+ +------------+ +---------+ | | | | +--------+---> | +------------+ +------------+ - +---------+ | - | | - | -+-------+---> | | - | | - | -- +---------+ | - | | - | --+------+---> | +------------+ +------------+ --- +---------+ | 64 573 | | 64 573 -+-+-- +----+---> | +------------+ +------------+ -- - +---------+ | 65 647 | | 65 647 -+--+- 690 | | +------------+ +------------+ - - +---------+ | 66 595 | | 66 595 -+---+ 691 +|---> | +------------+ +------------+ - -+---------+ | | | | - - +------------+ +------------+ - - | - | | - | - - | - | | - | - - +------------+ +------------+ - - |128 401 | |128 401 -+-----+ - +------------+ +------------+ - | | |129 ... -+---------+ +------------+ +------------+ | | +------------+ 9.8. . - , ( ). , , (. 9.8). - , - . . 9.1.3 ()  ( ) , - . - ( 7.9). - , , - , . (, , ) ( - ), ; 260 . , , - , . , ; . 8, . - , , "- , ", , (. 9.9). , , , . , . , , , , . : * , - . , , . ( 6.1). * , , - . - , . , . , ; , , , . , - , , - . - . , , , , , , nice, . , , - 2 , , , - , 2 - . , , , , , 2 (**) , , - , . - . --------------------------------------- (**) 6 UNIX , - 3 . - 2 . - , - . 261 +------------------------------------------------------------+ | swapper /* , | | * | | * */ | | : | | : | | { | | loop: | | ( , )| | , -| | ; | | ( ) | | { | | ( , -| | ); | | loop; | | } | | ( - | | ) | | { | | ; | | loop; | | } | | /* loop2: , - | | * */ | | ( , , | | | | ) | | { | | ( ) | | , | | - | | ; | | /* - | | * */ | | , - | | nice| | ; | | } | | ( | | ) | | ( , - | | ); | | | | ; | | loop; /* loop2 -| | * */ | | } | +------------------------------------------------------------+ 9.9. , - , . , - ( ), 262 . 9.10 . , ; , - 1 . , - , . , - . A B, . - , - ( ), 2 - A B C D. E, , - . 3- E , 3 , , 2 . 4- C D E A. , - . - - , , - . , "" - (. [Peachey 84]). , , . -, , - nice. , - - , , . , 1 , , , 2 - . , , . PDP 11/23 - , - 10 (. [Peachey 84]). -, , , , , . , , . - , . - , - - , ( 9.9). -, , - " ", , - . 9.11, , - 263 D 2- , C, 3- D E ( - nice), , D - . , . . , , : A B C D E --+--------------+-----------+-----------+-----------+----------- 0| 0 | 0 | | | | | | 0 | 0 | 0 | | | | | | | | | | | | | | | | | | | | --+- 1 | 1 | 1 | 1 | 1 1| | | | | | | | | | | | | | | | | | | | | | | | | --+- 2 |