process descript ion and cont rol
play

Process Descript ion and Cont rol 1 Process:t he concept Pr ocess - PowerPoint PPT Presentation

Process Descript ion and Cont rol 1 Process:t he concept Pr ocess = a pr ogr am in execut ion Example pr ocesses: OS ker nel OS shell Pr ogr am execut ing af t er compilat ion www-br owser Pr ocess management by OS :


  1. Process Descript ion and Cont rol 1

  2. Process:t he concept Pr ocess = a pr ogr am in execut ion • Example pr ocesses: – OS ker nel – OS shell – Pr ogr am execut ing af t er compilat ion – www-br owser Pr ocess management by OS : – Allocat e r esour ces – Schedule: int er leave t heir execut ion (wat ch f or pr ocessor ut ilizat ion, r esponse t ime) – I nt er pr ocess communicat ion, synchr onizat ion (wat ch f or deadlocks; int er leaving, nondet er minism imply incr eased dif f icult ies!) 2

  3. Two-St at e Process Model • Pr ocess may be in one of t wo st at es – Running, Not -r unning – Not -Running Pr ocess in a Queue 3

  4. What are not -running processes doing? 4

  5. Act ually t here are more queues … Obser ve: I / O’s much slower t han CPU What if all pr ocesses ar e wait ing f or I O and all memor y is allocat ed? Or if not enough memor y f or all pr ocesses t o execut e? Or if ... 5

  6. Suspended Processes I dea: Swap t hese processes t o disk t o f ree up more memory (t o admit new processes) • Blocked st at e becomes suspend st at e when swapped t o disk 6

  7. Two Suspend St at es 7

  8. Reasons f or Process Suspension e.g. t o prevent deadlock 8

  9. OS Cont rol St ruct ures What a pr ocess needs in or der t o execut e (pr ocess’ image): • Pr ogr am • Dat a • St ack • Pr ocess Cont r ol Block (cont ext ; f or mult ipr ogr amming) The OS must keep: • I nf or mat ion about t he cur r ent st at us of each pr ocess and r esour ce • Tables ar e const r uct ed f or each ent it y t he oper at ing syst em manages 10

  10. Process Table (and ot her OS t ables) Each ent r y: • Wher e pr ocess is locat ed • At t r ibut es necessar y f or it s management – Process I D – Process st at e – Locat ion in memory – Et c: process cont rol block • Ot her t ables hold r esour ce-specif ic inf o (zoom int o lat er ): – How main/ secondary memory is allocat ed, – I / O device st at us, buf f er in memory,… – File st at us, locat ion, 11 at t ribut es, …

  11. Process Cont rol Block PCB cont ains : • I dent if ier s (pr ocess, par ent pr ocess, user , … ) • Pr ocessor St at e I nf or mat ion (r egist er values: must be copied and r est or ed in st at e t r ansit ions: r unning  r eady,… ) • Ot her Pr ocess Cont r ol I nf or mat ion: – Scheduling and St at e I nf ormat ion (priorit y, event await ed, … ) – Process memory t ables – Resources (open f iles, ownership, … ) – Links (t o ot her process in a queue, … ) – Privileges – … 12

  12. Process Creat ion Examples: • Execut ion of a compiled user program • User logs on (shell st art s execut ing) • Process creat ion t o provide a service (e.g. print ing: user execut es lpr) • A process creat es anot her process (e.g. shell creat es lpr; user programs can creat e processes, as well) OS must : • Assign a unique process ident if ier • Allocat e space f or t he process • I nit ialize process cont rol block • Set up appropriat e linkages – “I nclude” t he process in t he syst em (in some queue(s), … ) 13

  13. When t o Swit ch a Running Process • Clock int er r upt – pr ocess has execut ed f or t he maximum allowable t ime slice • I / O int er r upt • Memor y f ault – memor y addr ess is in vir t ual memor y so it must be br ought int o main memor y • Tr ap – er r or occur r ed – may cause pr ocess t o be moved t o Exit st at e • Super visor call (or syst em call) – such as f ile open 14

  14. Change of Process St at e (cont ext swit ching) r unning  ot her • Save cont ext of pr ocessor including pr ogr am count er and ot her r egist er s (in PCB) • Move PCB t o appr opr iat e queue (r eady, blocked, … ) • Select anot her pr ocess f or execut ion • Updat e t he PCB of t he pr ocess select ed • Updat e memor y-management dat a st r uct ur es • Rest or e cont ext (in pr ocessor ) of t he select ed pr ocess 15

  15. Modes of Execut ion • User mode – Less-pr ivileged mode – User pr ogr ams t ypically execut e in t his mode • Syst em mode, cont r ol mode, or ker nel mode – Mor e-pr ivileged mode – Ker nel of t he oper at ing syst em 16

  16. Execut ion of t he Operat ing Syst em • Non-pr ocess Ker nel – oper at ing syst em code is execut ed as a separ at e ent it y t hat oper at es in pr ivileged mode • Pr ocess-Based Oper at ing Syst em – maj or ker nel f unct ions ar e separ at e pr ocesses – Usef ul in mult i-pr ocessor or mult i-comput er envir onment • Execut ion Wit hin User Pr ocesses – oper at ing syst em sof t war e wit hin cont ext of a user pr ocess – pr ocess execut es in pr ivileged mode when execut ing oper at ing 17 syst em code

  17. Threads 18

  18. Processes and Threads mult it hr eading: mor e t han one ent it ies can possibly execut e in t he same r esour ce- (i.e. pr ocess-) envir onment (and collabor at e bet t er ) Unit of … • … dispat ching is r ef er red t o as a t hr ead • … r esour ce owner ship is r ef er red t o as a pr ocess or t ask 19

  19. A process has … A t hread has … • an execut ion st at e, • a vir t ual addr ess space which st ack and cont ext holds t he pr ocess image (saved when not • global var iables, f iles, child r unning) pr ocesses, signals and signal • access t o t he memor y handler s and r esour ces of it s pr ocess – all t hreads of a process share t his • some per -t hr ead st at ic st or age f or local var iables 20

  20. Suspension and t erminat ion • Suspending a process involves suspending all t hreads of t he process since all t hreads share t he same address space • Terminat ion of a process, t erminat es all t hreads wit hin t he process 21

  21. Benef it s of Threads • Since t hreads wit hin t he same process share memory and f iles, t hey can communicat e wit h each ot her wit hout invoking t he kernel • May allow parallelizat ion wit hin a process: – I / O and comput at ion t o over lap (r emember t he hist or ical st ep f r om unipr ogr amming t o mult ipr ogr amming?) – concur r ent execut ion in mult ipr ocessor s • Takes less t ime t o – cr eat e/ t er minat e a t hr ead t han a pr ocess – swit ch bet ween t wo t hr eads wit hin t he same pr ocess 22

  22. Uses of Threads • Overlap f oreground (int eract ive) wit h background (processing) work • Asynchronous processing (e.g. backup while edit ing) • Speed execut ion (parallelize independent act ions) • Modular program st ruct ure (must be caref ul here, not t o int roduce t oo much ext ra overhead) Q: can one achieve parallelism wit hin a process 23 but wit hout using t hreads?

  23. I mplement ing Threads in User Space The kernel is not aware of t he exist ence of t hreads; • Run-t ime syst em (t hr ead- libr ar y in execut ion) is r esponsible f or bookkeeping, scheduling of t hr eads • allows f or cust omised scheduling • can r un on any OS • But : pr oblem wit h blocking syst em calls (when a t hr ead blocks, t he whole pr ocess blocks; i.e ot her t hr eads of t he same pr ocess cannot r un) 24 Fig: Tanenbaum, Modern OS, 2/ e

  24. I mplement ing Threads in t he Kernel Kernel maint ains cont ext inf ormat ion f or t he process and t he t hreads • Scheduling is done on a t hr ead basis • Does not suf f er f r om “blocking pr oblem” • Less ef f icient t han user -level t hr eads (ker nel is invoked f or t hr ead cr eat ion, t er minat ion, swit ching) 25 Fig: Tanenbaum, Modern OS, 2/ e

  25. Hybrid I mplement at ions Mult iplexing user-level t hreads ont o kernel- level t hreads To combine t he advant ages of t he ot her t wo appr oaches Fig: Tanenbaum, Modern OS, 2/ e 26

  26. 27

  27. Examples: • Posix Pt hr eads: (I EEE) st andar d: – Specif ies int er f ace – I mplement at ion (using user / ker nel level t hr eads) is up t o t he developer (s) – Mor e common in UNI X syst ems • Win32 t hr ead libr ar y: – Ker nel-level libr ar y, windows syst ems • J ava t hr eads: – Suppor t ed by t he J VM ( VM: a r un-t ime syst em, a gener al concept , wit h deeper r oot s and pot ent ial f ut ur e in t he OS wor ld ) – I mplement at ion is up t o t he developer s –e.g. can use Pt hr eads API or Win32 API , et c 28

  28. Examples (cont ) • W2K, XP: hybr id • Solaris: hybrid model model – User -level t hr eads – Thr ead: ker nel (use – Light weight pr ocesses win32 API ) – Ker nel t hr eads • Fiber : user -level t hr ead (libr ar y) • Linux: Only ker nel- level – clone sys-call: uses par amet er s t o descr ibe amount of r esour ce shar ing – Clone can somet imes equal a f or k, i.e. new t hr ead can be ”new pr ocess” 29

  29. 30

  30. Scheduler Act ivat ions • Goal – mimic f unct ionalit y of kernel t hreads – gain per f or mance of user space t hr eads • Avoids unnecessary user/ kernel t ransit ions – Ker nel assigns vir t ual pr ocessor s t o each pr ocess – ”signals” (make upcalls) t o r un-t ime syst em upon blocking and unblocking of (user -level) t hr eads – let s r unt ime syst em allocat e t hr eads t o pr ocessor s • Concern: Fundament al reliance on kernel (lower layer) calling procedures in user space (higher layer) 31

Recommend


More recommend