P rograms vs P rocesses � A pr ogr am is passive 3: P rocesses � Sequence of commands wait ing t o be r un � A pr ocess is act ive � An inst ance of pr ogr am being execut ed Last Modif ied: � Ther e may be many pr ocesses r unning t he same 6/ 1/ 2004 11:53:05 AM pr ogr am � Also called j ob or t ask -1 -2 What makes up a process? Address Space Map Somet imes St ack Biggest Reserved f or � Address space (Space f or local var iables et c. Vir t ual OS For each nest ed pr ocedur e call) Address � Code St ack Point er � Data � St ack (nest ing of procedure calls made) Heap (Space f or memor y dynamically � Regist er values (including t he PC) allocat ed e.g. wit h malloc) � Resources allocat ed t o t he process St at ically declar ed var iables (Global var iables) � Memor y, open f iles, net wor k connect ions PC Code (Text Segment ) Ox0000 Somet imes Reserved f or Error Cat ching -3 -4 What kinds of processes are P rocess St at es t here? � Comput e bound/ I O bound � During t heir lif et ime, processes move bet ween various st at es � Long-running/ short-r unning � Ready – wait ing f or a t ur n t o use t he CPU � I nt eract ive/ bat ch � Running – cur r ent ly execut ing on t he CPU � Large/ small memory f oot print ☺ • How many processes can be in t his st at e? � Cooperat ing wit h ot her processes? � Wait ing – Unable t o use t he CPU because � … blocked wait ing f or an event � Ter minat ed/ Zombie – Finished execut ing but � How does t he OS cat egorize processes? st at e maint ained unt il par ent pr ocess r et r ieves st at e -5 -6 1
St at e Transit ions St at e Queues � OSes of t en maint ain a number of queues of processes t hat represent t he st at e of t he processes Schedule/ unschedule New Ready Running Terminat ed � All t he r unnable pr ocesses ar e linked t oget her int o one queue Gr ant Resour ce Request Resource or Service � All t he pr ocesses blocked (or per haps blocked Wait ing f or a par t icular class of event ) ar e linked t oget her � As a pr ocess changes st at e, it is unlinked f r om one queue and linked int o anot her -7 -8 Cont ext Swit ch Cont ext Swit ch � When a process is running, some of it s st at e is st ored direct ly in t he CPU (regist er values, et c.) � When t he OS st ops a process, it must save all of t his hardware st at e somewhere (PCB) so t hat it can be r est or ed again � The act of saving one processes hardware st at e and rest oring anot her’s is called a cont ext swit ch � 100s or 1000s per second! -9 -10 Schedulers Schedulers (cont ) � Shor t-t er m scheduler is invoked ver y f r equent ly (milliseconds) ⇒ (must be f ast ). � Long-t erm scheduler (or j ob scheduler) – � Long-t er m scheduler is invoked ver y inf r equent ly select s which processes should be brought (seconds, minut es) ⇒ (may be slow). int o t he ready queue. � The long-t er m scheduler cont r ols t he degr ee of � Short-t erm scheduler (or CPU scheduler) – mult ipr ogr amming. select s which process should be execut ed � Pr ocesses can be descr ibed as eit her : next and allocat es CPU. � I / O- bound process – spends more t ime doing I / O t han comput at ions, many short CP U burst s. � CPU - bound process – spends more t ime doing comput at ions; f ew very long CP U burst s. -11 -12 2
Recommend
More recommend