OS-HW2.pdf

‫ﺑﻪ ﻧﺎﻡ ﺧﺪﺍ‬
‫ﺳﻴﺴﺘﻢ ﻫﺎﻱ ﻋﺎﻣﻞ‬
‫ﮔﺮﻭﻩ ‪) 1‬ﺍﺳﺘﺎﺩ‪ :‬ﺩﻛﺘﺮ ﺟﻠﻴﻠﻲ(‬
‫ﺗﻤﺮﻳﻨﺎﺕ ﺳﺮﻱ ﺩﻭﻡ )ﻓﺼﻞ ﻫﺎﻱ ‪ 4 ،3‬ﻭ ‪(5‬‬
‫‪.1‬‬
‫ﺗﺮﻡ ﭘﺎﻳﻴﺰ ‪1389‬‬
‫ﻣﻬﻠﺖ ﺗﺤﻮﻳﻞ‪89/8/30 :‬‬
‫ﺍﻟﻒ( ﻫﺮ ﻳﻚ ﺍﺯ ﻣﻔﺎﻫﻴﻢ ﺯﻳﺮ ﺭﺍ ﺑﻄﻮﺭ ﻣﺨﺘﺼﺮ ﺗﻮﺿﻴﺢ ﺩﻫﻴﺪ‪:‬‬
‫•‬
‫•‬
‫•‬
‫•‬
‫‪Swapping‬‬
‫‪Spooling‬‬
‫‪Buffering‬‬
‫‪Dispatcher‬‬
‫ﺏ( ﺭﺍﻩ ﻫﺎﻱ ﻣﺨﺘﻠﻔﻲ ﻛﻪ ﻣﻲ ﺗﻮﺍﻥ ﻳﻚ ﻧﺦ ﺭﺍ ﻣﻠﻐﻲ ﻛﺮﺩ ﻧﺎﻡ ﺑﺮﺩﻩ ﻭ ﻫﺮ ﻳﻚ ﺭﺍ ﺑﻄﻮﺭ ﻣﺨﺘﺼﺮ ﺗﻮﺿﻴﺢ ﺩﻫﻴﺪ‪.‬‬
‫ﺝ( ﻛﺎﺭﻫﺎﻳﻲ ﻛﻪ ﺗﻮﺳﻂ ﺳﻴﺴﺘﻢ ﻋﺎﻣﻞ ﺑﺮﺍﻱ ﺗﻌﻮﻳﺾ ﻣﺘﻦ ﺩﺭ ﻫﺮ ﻳﻚ ﺍﺯ ﻣﻮﺍﺭﺩ ﺯﻳﺮ ﺍﻧﺠﺎﻡ ﻣﻲ ﺷﻮﺩ ﺭﺍ ﺗﻮﺿﻴﺢ ﺩﻫﻴﺪ‪.‬‬
‫‪ -‬ﺑﻴﻦ ﻓﺮﺁﻳﻨﺪﻫﺎ‬
‫ ﺑﻴﻦ ﻧﺦ ﻫﺎ‬‫‪.2‬‬
‫ﻳﻚ ﻓﺮﺁﻳﻨﺪ ﻳﺎ ﻧﺦ�‪ ،‬ﻣﻲ ﺗﻮﺍﻧﺪ ﺷﺎﻣﻞ ﻫﻤﻪ ﻳﺎ ﺑﺮﺧﻲ ﺍﺯ ﻣﻮﻟﻔﻪ ﻫﺎﻱ ﺯﻳﺮ ﺑﺎﺷﺪ‪.‬‬
‫‪F0‬‬
‫)‪ (1‬ﻣﻘﺎﺩﻳﺮ ﺭﺟﻴﺴﺘﺮ‬
‫)‪ (2‬ﺣﺎﻓﻈﻪ ‪heap‬‬
‫)‪ (3‬ﻣﺘﻐﻴﺮﻫﺎﻱ ﻋﻤﻮﻣﻲ‬
‫)‪ (4‬ﺣﺎﻓﻈﻪ ﭘﺸﺘﻪ‬
‫)‪TCB (5‬‬
‫)‪PCB (6‬‬
‫)‪ (7‬ﺳﮕﻤﻨﺖ ﺩﺍﺩﻩ‬
‫)‪ (8‬ﺳﮕﻤﻨﺖ ﻛﺪ‬
‫ﻛﺪﺍﻡ ﻳﻚ ﺍﺯ ﺍﻳﻦ ﻣﻮﻟﻔﻪ ﻫﺎ ﺗﻮﺳﻂ ﺟﻔﺖ ﻫﺎﻱ ﺯﻳﺮ ﺑﺼﻮﺭﺕ ﻣﺸﺘﺮﻙ ﺍﺳﺘﻔﺎﺩﻩ ﻣﻲ ﺷﻮﺩ؟‬
‫ﺍﻟﻒ( ﻳﻚ ﻓﺮﺁﻳﻨﺪ ﭼﻨﺪﻧﺨﻲ ﻭ ﻳﻜﻲ ﺍﺯ ﻧﺦ ﻫﺎﻱ ﺁﻥ‬
‫ﺏ( ﻫﺮ ﺩﻭ ﻧﺦ ﺩﺭ ﻳﻚ ﻓﺮﺁﻳﻨﺪ ﭼﻨﺪ ﻧﺨﻲ‬
‫ﺝ( ﻫﺮ ﺩﻭ ﻓﺮﺁﻳﻨﺪ ﻓﺮﺯﻧﺪ ﺍﺯ ﻳﻚ ﻓﺮﺁﻳﻨﺪ ﭘﺪﺭ‬
‫‪.3‬‬
‫ﻫﺮ ﻓﺮﺁﻳﻨﺪ ﻣﻲ ﺗﻮﺍﻧﺪ ﺩﺭ ﻳﻜﻲ ﺍﺯ ﺣﺎﻻﺕ‪ :‬ﺁﻣﺎﺩﻩ‪ ،‬ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍ‪ ،‬ﻣﻨﺘﻈﺮ ﻭ ﺧﺎﺗﻤﻪ ﻳﺎﻓﺘﻪ ﺑﺎﺷﺪ‪ .‬ﭼﻪ ﺍﺗﻔﺎﻗﺎﺗﻲ ﻣﻲ ﺗﻮﺍﻧﺪ ﻣﻮﺟﺐ ﺗﻐﻴﻴﺮ ﺣﺎﻟﺖ ﻫﺎﻱ ﺯﻳﺮ‬
‫ﺷﻮﺩ‪:‬‬
‫ﺍﻟﻒ( ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍ ﺑﻪ ﺁﻣﺎﺩﻩ‬
‫ﺏ( ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍ ﺑﻪ ﻣﻨﺘﻈﺮ‬
‫‪thread‬‬
‫‪1‬‬
‫ﺝ( ﻣﻨﺘﻈﺮ ﺑﻪ ﺁﻣﺎﺩﻩ‬
‫ﺩ( ﻣﻨﺘﻈﺮ ﺑﻪ ﺧﺎﺗﻤﻪ ﻳﺎﻓﺘﻪ‬
‫‪.4‬‬
‫ﺍﻟﻒ( ﺑﺮﺍﻱ ﻓﺮﺁﻳﻨﺪ ﺯﻳﺮ ﻧﻤﻮﺩﺍﺭ ﮔﺬﺭ ﺁﻧﺮﺍ ﺭﺳﻢ ﻛﻨﻴﺪ‪.‬‬
‫‪ -‬ﻓﺮﺽ ﻛﻨﻴﺪ ﺗﻨﻬﺎ ﺍﻳﻦ ﻓﺮﺁﻳﻨﺪ ﺩﺭ ﺳﻴﺴﺘﻢ ﻭﺟﻮﺩ ﺩﺍﺭﺩ ﻭ ﻛﺪ ﺍﺟﺮﺍﻳﻲ ﻗﺒﻼ ﺩﺭ ﺳﻴﺴﺘﻢ ﺑﺎﺭﮔﺬﺍﺭﻱ ﺷﺪﻩ ﺍﺳﺖ‪.‬‬
‫ ﺑﺮﺍﻱ ﻫﺮ ﺣﺎﻟﺖ‪ ،‬ﻋﺒﺎﺭﺗﻲ ﺭﺍ ﻛﻪ ﺍﺟﺮﺍ ﺧﻮﺍﻫﺪ ﻛﺮﺩ ﺭﺍ ﻣﺸﺨﺺ ﻛﻨﻴﺪ‪ .‬ﺍﮔﺮ ﻳﻚ ﺣﺎﻟﺖ ﺑﻴﺶ ﺍﺯ ﻳﻚ ﺑﺎﺭ ﺍﺗﻔﺎﻕ ﻣﻲ ﺍﻓﺘﺪ‪ ،‬ﺁﻧﺮﺍ ﭼﻨﺪﻳﻦ ﺑﺎﺭ‬‫ﻧﻤﺎﻳﺶ ﺩﻫﻴﺪ‪.‬‬
‫ ﻫﺮ ﻋﺒﺎﺭﺕ ‪ I/O‬ﺭﺍ ﻳﻚ ﺩﺳﺘﻮﺭ ﺟﺪﺍﮔﺎﻧﻪ ﺑﺮﺍﻱ ﭘﺮﺩﺍﺯﻧﺪﻩ ﺩﺭ ﻧﻈﺮ ﺑﮕﻴﺮﻳﺪ‪.‬‬‫)(‪int main‬‬
‫{‬
‫;‪int i,j‬‬
‫;‪ofstream myfile‬‬
‫;‪i=100‬‬
‫;‪j=2*i‬‬
‫;)"‪myfile.open("example.txt‬‬
‫;"‪myfile<<"Writing this to a file.\n‬‬
‫;)(‪myfile.close‬‬
‫;‪j=j*2‬‬
‫;‪cout<<j<<endl‬‬
‫;‪return 0‬‬
‫}‬
‫ﺏ( ﻓﺮﺽ ﻛﻨﻴﺪ ﻫﺮ ﺍﺟﺮﺍﻱ ﻫﺮ ﺩﺳﺘﻮﺭ ‪ 1‬ﻭﺍﺣﺪ ﺯﻣﺎﻧﻲ ﻃﻮﻝ ﻣﻲ ﻛﺸﺪ‪ .‬ﺗﻌﻮﻳﺾ ﻣﺘﻦ ‪ 5‬ﻭﺍﺣﺪ ﺯﻣﺎﻧﻲ ﻭ ﻫﺮ ﻋﻤﻞ ‪ 20 ،I/O‬ﻭﺍﺣﺪ ﺯﻣﺎﻧﻲ ﻃﻮﻝ ﻣﻲ‬
‫ﻛﺸﺪ‪ .‬ﻛﻞ ﺯﻣﺎﻥ ﻻﺯﻡ ﺑﺮﺍﻱ ﺍﺟﺮﺍﻱ ﻓﺮﺁﻳﻨﺪ ﺑﺎﻻ ﺍﺯ ﺯﻣﺎﻧﻲ ﻛﻪ ﺩﺭ ﺳﻴﺴﺘﻢ ﺑﺎﺭﮔﺬﺍﺭﻱ ﺷﺪﻩ ﺗﺎ ﺍﺗﻤﺎﻡ ﺁﻥ ﺭﺍ ﻣﺤﺎﺳﺒﻪ ﻛﻨﻴﺪ‪.‬‬
‫‪.5‬‬
‫ﺷﺒﻪ ﻛﺪﻱ ﺑﻨﻮﻳﺴﻴﺪ ﻛﻪ ﺩﺭﺧﺖ ﻓﺮﺁﻳﻨﺪﻱ ﺑﺼﻮﺭﺕ ﺷﻜﻞ ﺯﻳﺮ ﺑﻮﺟﻮﺩ ﺁﻭﺭﺩ‪ ،‬ﺑﻄﻮﺭﻳﻜﻪ ‪:‬‬
‫‪ ،P5 -‬ﺑﺮﻧﺎﻣﻪ ﺍﻱ ﺑﻪ ﻧﺎﻡ ‪ sort‬ﺭﺍ ﺍﺟﺮﺍ ﻣﻲ ﻛﻨﺪ‪.‬‬
‫‪ ،P4 -‬ﺑﺮﻧﺎﻣﻪ ﺍﻱ ﺑﻪ ﻧﺎﻡ ‪ permutation‬ﺭﺍ ﺍﺟﺮﺍ ﻣﻲ ﻛﻨﺪ‪.‬‬
‫ ‪ ،P2‬ﺗﺎ ﺧﺎﺗﻤﻪ ﻓﺮﺁﻳﻨﺪ ‪ ،P3‬ﺻﺒﺮ ﻣﻲ ﻛﻨﺪ ﻭ ﺳﭙﺲ ﻓﺮﺁﻳﻨﺪ ‪ P4‬ﺭﺍ ﺍﺯ ﺑﻴﻦ ﻣﻲ ﺑﺮﺩ‪.‬‬‫‪P1‬‬
‫‪P2‬‬
‫‪P3‬‬
‫‪P5‬‬
‫‪P4‬‬
‫‪.6‬‬
‫ﺩﺭﺳﺘﻲ ﻳﺎ ﻧﺎﺩﺭﺳﺘﻲ ﻋﺒﺎﺭﺍﺕ ﺯﻳﺮ ﺭﺍ ﺗﻌﻴﻴﻦ ﻛﺮﺩﻩ ﻭ ﺑﺮﺍﻱ ﭘﺎﺳﺦ ﺧﻮﺩ ﺗﻮﺿﻴﺢ ﻣﺨﺘﺼﺮﻱ ﺑﻨﻮﻳﺴﻴﺪ‪.‬‬
‫ﺍﻟﻒ( ﺑﺮﺵ ﺯﻣﺎﻧﻲ ﻛﻮﭼﻚ ﻫﻤﻮﺍﺭﻩ ﻣﺘﻮﺳﻂ ﺯﻣﺎﻥ ﺧﺎﺗﻤﻪ ﻳﻚ ﺳﻴﺴﺘﻢ ﺭﺍ ﺑﻬﺒﻮﺩ ﻣﻲ ﺑﺨﺸﺪ‪.‬‬
‫�‬
‫ﺏ( ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺯﻣﺎﻧﺒﻨﺪ ‪ ،round robin‬ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﺑﺮﺵ ﺯﻣﺎﻧﻲ ﺑﺰﺭگ ﺑﺮﺍﻱ ﻛﺎﺭﺑﺮﺍﻥ ﻣﺤﺎﻭﺭﻩ ﺍﻱ ﺧﻮﺏ ﻧﻴﺴﺖ‪.‬‬
‫‪F1‬‬
‫ﺝ( ‪ SJF‬ﺑﺮﺍﻱ ﭘﻴﺎﺩﻩ ﺳﺎﺯﻱ ﺭﻭﻱ ﻳﻚ ﺳﻴﺴﺘﻢ ﻋﺎﻣﻞ ﻭﺍﻗﻌﻲ‪ ،‬ﺩﺷﻮﺍﺭ ﺍﺳﺖ‪.‬‬
‫‪.7‬‬
‫‪ 5‬ﻓﺮﺁﻳﻨﺪ ﺑﺎ ﻣﺸﺨﺼﺎﺕ ﺯﻳﺮ ﻭﺟﻮﺩ ﺩﺍﺭﺩ‪.‬‬
‫ﻓﺮﺁﻳﻨﺪ‬
‫ﺯﻣﺎﻥ ﻭﺭﻭﺩ‬
‫ﺯﻣﺎﻥ ﺳﺮﻭﻳﺲ‬
‫‪A‬‬
‫‪B‬‬
‫‪C‬‬
‫‪D‬‬
‫‪E‬‬
‫‪0‬‬
‫‪2‬‬
‫‪4‬‬
‫‪6‬‬
‫‪8‬‬
‫‪3‬‬
‫‪6‬‬
‫‪4‬‬
‫‪5‬‬
‫‪2‬‬
‫ﻣﺘﻮﺳﻂ ﺯﻣﺎﻥ ﭘﺎﺳﺨﮕﻮﻳﻲ� ﻭ ﻣﺘﻮﺳﻂ ﺯﻣﺎﻥ ﺍﻧﺘﻈﺎﺭ� ﺭﺍ ﺑﺮﺍﻱ ﻫﺮ ﻳﻚ ﺍﺯ ﺭﻭﺵ ﻫﺎﻱ ﺯﻣﺎﻧﺒﻨﺪﻱ ‪ RR ،HRRN ،SRT ،SJF ،FCFS‬ﺑﺎ ﻛﻮﺍﻧﺘﻮﻡ‬
‫‪F3‬‬
‫‪F2‬‬
‫ﺯﻣﺎﻧﻲ ‪ 1‬ﻣﻴﻠﻲ ﺛﺎﻧﻴﻪ‪ RR ،‬ﺑﺎ ﻛﻮﺍﻧﺘﻮﻡ ﺯﻣﺎﻧﻲ ‪ 4‬ﻣﻴﻠﻲ ﺛﺎﻧﻴﻪ‪ MLFQ ،‬ﺑﺎ )‪ MLFQ ،RR(q=1‬ﺑﺎ )‪ RR(q=2‬ﻣﺤﺎﺳﺒﻪ ﻛﻨﻴﺪ‪ .‬ﺑﺮﺍﻱ ﻫﺮ ﺭﻭﺵ ﻧﻤﻮﺩﺍﺭ‬
‫ﮔﺎﻧﺖ ﻧﻴﺰ ﺭﺳﻢ ﺷﻮﺩ‪.‬‬
‫‪.8‬‬
‫‪ 4‬ﻓﺮﺁﻳﻨﺪ ﺑﺎ ﻣﺸﺨﺼﺎﺕ ﺯﻳﺮ ﻭﺟﻮﺩ ﺩﺍﺭﺩ‪:‬‬
‫ﻓﺮﺁﻳﻨﺪ‬
‫ﺯﻣﺎﻥ ﻭﺭﻭﺩ‬
‫ﺯﻣﺎﻥ ﺳﺮﻭﻳﺲ‬
‫ﺍﻭﻟﻮﻳﺖ‬
‫‪A‬‬
‫‪B‬‬
‫‪C‬‬
‫‪D‬‬
‫‪10‬‬
‫‪15‬‬
‫‪20‬‬
‫‪25‬‬
‫‪15‬‬
‫‪5‬‬
‫‪10‬‬
‫‪5‬‬
‫‪4‬‬
‫‪3‬‬
‫‪2‬‬
‫‪1‬‬
‫ﺍﻟﻒ( ﻣﺘﻮﺳﻂ ﺯﻣﺎﻥ ﭘﺎﺳﺨﮕﻮﻳﻲ ﻭ ﻣﺘﻮﺳﻂ ﺯﻣﺎﻥ ﺍﻧﺘﻈﺎﺭ ﺭﺍ ﺑﺮﺍﻱ ﺭﻭﺵ ﺯﻣﺎﻧﺒﻨﺪﻱ ‪ SJF‬ﺍﻧﺤﺼﺎﺭﻱ� ﻣﺤﺎﺳﺒﻪ ﻛﻨﻴﺪ‪ .‬ﻧﻤﻮﺩﺍﺭ ﮔﺎﻧﺖ ﻭ ﺩﻳﮕﺮ‬
‫‪F4‬‬
‫ﺟﺰﺋﻴﺎﺕ ﻻﺯﻡ ﻧﻤﺎﻳﺶ ﺩﺍﺩﻩ ﺷﻮﺩ‪) .‬ﺩﺭ ﺻﻮﺭﺕ ﻭﺟﻮﺩ ﺗﺴﺎﻭﻱ‪ ،‬ﺍﻭﻟﻮﻳﺖ ﺑﺎ ﭘﺮﺩﺍﺯﺵ ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍﺳﺖ‪(.‬‬
‫ﺏ( ﻗﺴﻤﺖ )ﺍﻟﻒ( ﺭﺍ ﺑﺎ ﺩﺭ ﻧﻈﺮ ﮔﺮﻓﺘﻦ ﺭﻭﺵ ﺯﻣﺎﻧﺒﻨﺪﻱ ‪ round-robin‬ﺑﺎ ﻛﻮﺍﻧﺘﻮﻡ ﺯﻣﺎﻧﻲ ‪ 5‬ﻭﺍﺣﺪ ﭘﺎﺳﺦ ﺩﻫﻴﺪ‪.‬‬
‫ﺝ( ﻓﺮﺽ ﻛﻨﻴﺪ ﺗﻌﻮﻳﺾ ﻣﺘﻦ ‪ 0.1‬ﻭﺍﺣﺪ ﺯﻣﺎﻧﻲ ﻃﻮﻝ ﻣﻲ ﻛﺸﺪ‪ .‬ﺩﺭﺻﺪ ﺳﺮﺑﺎﺭ ﻧﺎﺷﻲ ﺍﺯ ﺗﻌﻮﻳﺾ ﻣﺘﻦ ﺭﺍ ﺑﺮﺍﻱ ﻫﺮ ﻳﻚ ﺍﺯ ﺩﻭ ﺭﻭﺵ ﺫﻛﺮ ﺷﺪﻩ‬
‫ﻣﺤﺎﺳﺒﻪ ﻛﻨﻴﺪ‪.‬‬
‫‪2‬‬
‫‪interactive‬‬
‫‪Turnaround time‬‬
‫‪4‬‬
‫‪Waiting time‬‬
‫‪5‬‬
‫‪preemptive‬‬
‫‪3‬‬
‫‪.9‬‬
‫ﺩﺭ ﺳﻴﺴﺘﻤﻲ ﺯﻣﺎﻥ ﺗﻌﻮﻳﺾ ﻣﺘﻦ ‪ S‬ﺑﻮﺩﻩ ﻭ ﺍﺯ ﺳﻴﺎﺳﺖ ‪ RR‬ﺑﺎ ﺑﺮﺵ ﺯﻣﺎﻧﻲ ‪ Q‬ﺑﺮﺍﻱ ﺯﻣﺎﻧﺒﻨﺪﻱ ﺍﺳﺘﻔﺎﺩﻩ ﻣﻲ ﺷﻮﺩ‪ .‬ﺍﮔﺮ ﻣﺘﻮﺳﻂ ﺯﻣﺎﻥ ﺍﺟﺮﺍﻱ ﻫﺮ‬
‫ﻓﺮﺁﻳﻨﺪ ﻗﺒﻞ ﺍﺯ ﺑﻠﻮﻛﻪ ﺷﺪﻥ ﺑﻪ ﺩﻟﻴﻞ ﻋﻤﻞ ‪ T ،I/O‬ﺑﺎﺷﺪ‪ ،‬ﺩﺭ ﻫﺮ ﻳﻚ ﺍﺯ ﺣﺎﻻﺕ ﺯﻳﺮ ﻛﺎﺭﺍﻳﻲ ﭘﺮﺩﺍﺯﻧﺪﻩ ﺭﺍ ﺑﺪﺳﺖ ﺁﻭﺭﻳﺪ‪.‬‬
‫ﺍﻟﻒ( ‪Q=0‬‬
‫ﺏ( ‪Q>T‬‬
‫ﺝ( ‪S<Q<T‬‬
‫ﺩ( ‪Q=S‬‬
‫‪ .10‬ﺗﻔﺎﻭﺕ ﻫﺎ ﻭ ﺷﺒﺎﻫﺖ ﻫﺎﻱ ﺳﻴﺴﺘﻢ ﻋﺎﻣﻞ ﻫﺎﻱ ﻟﻴﻨﻮﻛﺲ ﻭ ‪ BSD‬ﺭﺍ ﺫﻛﺮ ﻛﺮﺩﻩ)‪ 4‬ﻣﻮﺭﺩ ﻛﺎﻓﻲ ﺍﺳﺖ( ﻭ ‪ 3‬ﻧﺴﺨﻪ ﭘﺮﻛﺎﺭﺑﺮﺩ ‪ BSD‬ﺭﺍ ﺑﺎ ﻫﻢ ﻣﻘﺎﻳﺴﻪ‬
‫ﻛﻨﻴﺪ)ﻫﺮﻛﺪﺍﻡ ﺑﺮﺍﻱ ﭼﻪ ﻛﺎﺭﺑﺮﺩﻱ ﻃﺮﺍﺣﻲ ﺷﺪﻩ ﺍﺳﺖ؟(‬