2 | 2 | 2 | 2 2| | | | | | 0 | 0 | 0 | 0 | | | | | | | | | | | | | | | | --+- 1 | 1 | 1 | 1 | 3 3| | | | | | | | | | | | | | | | | | | | | | | | | --+- 2 | 2 | 2 | 2 | 4 4| | | | | | 0 | | 0 | 0 | 0 | | | | | | | | | | | | | | | --+- 1 | 3 | 1 | 1 | 1 5| | | | | | | | | | | | | | | | | | | | | | | | | --+- 2 | 4 | 2 | 2 | 2 6| | | | | | 0 | 0 | 0 | | 0 | | | | | | | | | | v 9.10. , 264 A B C D E --+--------------+-----------+-----------+-----------+----------- 0| 0 | 0 | | nice 25 | | | | 0 | | 0 | | | | 0 | | | | | | | | | | | | | | | | --+- 1 | 1 | 1 | 1 | 1 1| | | | | | | | | | | | | | | | | | | | | | | | | --+- 2 | 2 | 2 | 2 | 2 2| | | | | | 0 | 0 | 0 | 0 | | | | | | | | | | | | | | | | --+- 1 | 1 | 1 | 1 | 3 3| | | | | | | | | 0 | 0 | | | | | | | | | | | | | | | --+- 2 | 2 | 2 | 1 | 1 4| | | | | | 0 | | 0 | | | | | | | | | | | | | | | | | --+- 1 | 3 | 1 | 2 | 2 5| | | | | | | 0 | | | 0 | | | | | | | | | | | | | | | --+- 2 | 1 | 2 | 3 | 1 6| | | | | | 0 | | | 0 | | | | | | | | | | | v 9.11. , , , . 9.5. , , . 265 9.2  , (***). , . , - 1 2 4 5 . , , . - , - , . - , . , - , , - . "". [Denning 68] - , n - ; n - . , - , , - . , , , , . 9.12 - , "" ( - , ). - - ; - , , - . , - . - (reference bit) , . - , ; "" . - , , , . - , , - - . , : - - . , , . - V UNIX. --------------------------------------- (***) , , , - , , . 266 9.2.1 ,  () 4 - : , , (page frame data table - : pfdata) . pfdata , . 6 , , . ( 9.13) - , , ( , ), , : - - 2 3 4 5 +------------+ +-------+----------+-------------+----------------+ | 24 | | 24 | 24 | 24 | 24 | +------------+ | | | | | | 15 | | 15 24 | 15 24 | 15 24 | 15 24 | +------------+ | | | | | | 18 | | 18 15 | 18 15 24 | 18 15 24 | 18 15 24 | +------------+ | | | | | | 23 | | 23 18 | 23 18 15 | 23 18 15 24 | 23 18 15 24 | +------------+ | | | - | - | | 24 | | 24 23 | 24 23 18 | - | - | +------------+ | | | - | - | | 17 | | 17 24 | 17 24 23 | 17 24 23 18 | 17 24 23 18 15 | +------------+ | | | - | - | | 18 | | 18 17 | 18 17 24 | - | - | +------------+ | | - | - | - | | 24 | | 24 18 | - | - | - | +------------+ | | - | - | - | | 18 | | 18 24 | - | - | - | +------------+ | | - | - | - | | 17 | | 17 18 | - | - | - | +------------+ | | - | - | - | | 17 | | | - | - | - | +------------+ | | - | - | - | | 15 | | 15 17 | 15 17 18 | 15 17 18 24 | - | +------------+ | | | - | - | | 24 | | 24 15 | 24 15 17 | - | - | +------------+ | | - | - | - | | 17 | | 17 24 | - | - | - | +------------+ | | - | - | - | | 24 | | 24 17 | - | - | - | +------------+ | | - | - | - | | 18 | | 18 24 | 18 24 17 | - | - | +------------+ +-------+----------+-------------+----------------+ 9.12. * * 267 * * * "" , , , , , . , , - , - . , - fork, , , , - . , "" - . , "" , - - ; 9.2.4 , . +--------+ +->+----------------------+---------------------------+ | | | | | | | | | +----------------------+---------------------------+ | | | | | | | | | +----------------------+---------------------------+ | | | | | | | | | +----------------------+---------------------------+ | | | | | | | ----+-+ +----------------------+---------------------------+ | | | | | | | +----------------------+---------------------------+ | | | | | +--------+ +----------------------+---------------------------+ | | | +----------------------+---------------------------+ | | | +----------------------+---------------------------+ | | | +----------------------+---------------------------+ | | | +----------------------+---------------------------+ +-----------------------------+-------+-----+-----+----+-----+---+ | () ||-|-|-|- |-| | | |-|-|- |- |-| | | | | |- |- | | | | | | | || | | | |-| | | | | | | | | | | | | +-----------------------------+-------+-----+-----+----+-----+---+ +-----------------------+---------------+------------------------+ | | | ( - | | | | , | | | | , | | | | , - | | | | ) | +-----------------------+---------------+------------------------+ 9.13. 268 , ( 9.13). - , , . - , , . , - , . , ; . - exec : - ("demand fill") ("demand zero"). 9.2.1.2. pfdata . : * , , - , - ( - ), , . * , . , . , - , , - fork. * ( ) , . * pfdata - - . pfdata - -. , , , , , - , . . "- ". - - () . , , . , , -. - , . , , . 9.14 , , pfdata - . 1493 , 794; - , , , - 1 2743. pfdata, , , , , 1. , - pfdata, 9.2.4.1. ( - ) , 269 . 9.2.1.1 fork  7.1, fork - -. - +-----------------------+--------------------------+ | | | +-----------------------+--------------------------+ 1493 | 794 | 1 2743 | +---+-+-----------------+--------------------+-----+ | | | | | pfdata, | | | - +------------+ +------------+ v 794 | | +------------+-----------------------+ | | | | 1 | | | | +-----------------------+ | | | | 1 | | | | +-----------------------+ | +-----------------+ | | | 2743 | | | 1| | | +-----------------+-----+ | +--------+--------+ | | | +-----+ | | | | | +--------------+ v v v v v +--------------------------+ +---------------------------+ | 794 | | 2743 | +--------------------------+ +---------------------------+ 9.14. , - - -, , fork exec . , V ( , - pfdata). , , , - , - -: , pfdata, , - ( , ). - , - . , - , . - , , , . fork , - , " ". - , - , - . , - 270 , . 9.15. T, 2, ( pfdata). - - - +--------------+ +--------------+ | - | | - | +--------------+ +--------------+ | - - | | - - | +--------------+ +--------------+ - + ---------------------+ - - - - - v v v v +-------------------+ +-------------------+ +-------------------+ | T | | P1 | | C1 | | 2 | | 1 | | 1 | |+-----------------+| |+-----------------+| |+-----------------+| || || || || || || || || || || || || |+-----------------+| |+-----------------+| |+-----------------+| || - || || - || || - || || - || || - || || - || |+-----------------+| || - || || - || ||- -|| || - || || - || || || || - || || - || || 24 967 || || - || || - || |+-----------------+| |+-----------------+| |+-----------------+| || - - || ||- -|| ||- -|| || - - || || || || || || - - || || 97 613 || || 97 613 || || - - || |+-----------------+| |+-----------------+| || - - || || - - || || - - || || - - || || - - || || - - || |+-----------------+| |+-----------------+| |+-----------------+| +-------------------+ +-------------------+ +-------------------+ - - ----------- v v v +---------------------+ +---------------------+ | 967 | | 613 | | 1 | | 2 | +---------------------+ +---------------------+ 9.15. , - fork - C1, P1 - -. , 97. pfdata 613, 2, . fork BSD . , , , BSD 271 vfork, , fork exec. vfork , , fork V UNIX. - , , . vfork , , - . UNIX BSD , : - , , ? +------------------------------------------------------------+ | int global; | | main() | | { | | int local; | | | | local = 1; | | if (vfork() == 0) | | { | | /* */ | | global = 2; /* */| | local = 3; /* */ | | _exit(); | | } | | printf("global %d local %d\n",global,local); | | } | +------------------------------------------------------------+ 9.16. vfork , 9.16. vfork - exec, global local (****). , - - , exec exit. - , - , - , vfork ! -- , vfork (. 9.8). 9.2.1.2 exec  7, - exec, . , --------------------------------------- (****) exit _exit, "" , - ( - ), , printf, , - - vfork. 272 , - . , . , " " ( , bss) " " ( bss). read, - () . , " " ( ) " " ( ). 9.2.3 , . , "" , - . . -, - - - , . -, , "" , exec, . exec, , , .. " ". - , (, bmap) , - , , - . , bmap - , . read -. , , , - . . - , - . , - , exec . , , , ; - , +-> +---------------------------------+ | +----------------+ | -----------+-+ 0 | | | | - | | | | - | | | | - | | | +---------------------------+ | - | | | | 84 | | - +----------------+ | +---------------------------+ | 84 | 279 | | | +----------------+ +---------------------------------+ | | | | +----------------+ 9.17. 273 . 9.17 , - 84 - . , - (279). 9.2.2 ""  "" (page stealer) , , . , . - "" ( , - , , ). , , , , "" , . : "", , . , - . - , , , ( 9.2.4). , "" , , - . , , "" , (. 9.18). , - . - - . 9.19 , , "" . "- +------------+----------+----------+-----------------+ | ^ ^ ^ | v | | | | - +-------+ | | | | | - | +-+-+ +-+-+ +-+-+ +-+-+ | |----->| 1 +----->| 2 +----->| 3 +-------->| n | - | | +---+ +---+ +---+ +-+-+ - +-------+ "" --- | ^ | | | | +--------+ | | | -| | - +-----------------------| - |<------------------+ - | | +--------+ 9.18. 274 " , - . , "", "" 0. - , "" - . , , . , - , "" . , ; . , , , , : "" . "" , , , "" , - . - , , , . . , , , -