1 / 57

Processes and Threads

Processes and Threads. 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling. Chapter 2. Processes The Process Model. Multiprogramming of four programs Conceptual model of 4 independent, sequential processes

cael
Download Presentation

Processes and Threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Processes and Threads 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling Chapter 2

  2. ProcessesThe Process Model • Multiprogramming of four programs • Conceptual model of 4 independent, sequential processes • Only one program active at any instant

  3. Process Creation Principal events that cause process creation • System initialization • Execution of a process creation system • User request to create a new process • Initiation of a batch job

  4. Proceso sukūrimas Programinis kodas bus pradėtas vykdyti tik ta-da, kai jam OS bus sukurtas procesas: • Sukurti informacines struktūras, aprašančias procesą, t.y. jo deskriptorių ir kontekstą; • Įtraukti naujo proceso deskriptorių į paruoš-tų procesų eilę; • Užkrauti proceso kodo segmentą į operaty-viąją atmintį arba svopingo sritį.

  5. Proceso kontekstas - operacinės aplinkos būsena • registrų ir programinio skaitiklio būsena, • procesoriaus darbo režimo būsena, • atidarytų failų rodiklių būsenos, • informacija apie neužbaigtas įvedimo-išve-dimo operacijas, • šio proceso vykdomų sisteminių užklausų klaidų kodai ir t.t.

  6. Proceso deskriptorius • proceso identifikatorius, • proceso būsena, • duomenys apie proceso privilegijas, • kodo segmento vieta.

  7. Process Termination Conditions which terminate processes • Normal exit (voluntary) • Error exit (voluntary) • Fatal error (involuntary) • Killed by another process (involuntary)

  8. Procesų planavimo algoritmai Planuojant procesus, reikia išspręsti šiuos uždavinius: • Nustatyti vykdomo proceso pakeitimo laiką; • Iš paruoštų procesų eilės išrinkti procesą vykdymui; • „Seno“ ir „naujo“ procesų kontekstų perjungimas.

  9. Pagrindinės procesų planavimo algoritmų grupės • algoritmai, pagrįsti kvantavimu, • algoritmai, pagrįsti prioritetais .

  10. Kvantavimu pagrįstuose algoritmuose aktyvus procesas pakeičiamas, jeigu: • Procesas pasibaigė ir paliko sistemą, • Įvyko klaida, • Procesas perėjo į LAUKIMO būseną, • Pasibaigė procesorinio laiko kvantas, skirtas šiam procesui.

  11. Proceso būsenų grafas (kvantavimo algoritmas) VYKDYMAS PARUOŠTAS LAUKIMAS

  12. Algoritmai, pagrįsti procesų prioritetais Prioritetas – tai skaičius, charakterizuojantis proceso privilegijų laipsnį, naudojantis kompiu-terinės sistemos resursais, pvz., procesoriniu laiku: kuo aukštesnis prioritetas, tuo aukštesnės privilegijos.

  13. Dvi prioritetinių algoritmų grupės: • algoritmai, naudojantys santykinius priori-tetus, • algoritmai, naudojantys absoliutinius prio-ritetus.

  14. Algoritmai, naudojantys santykinius prioritetus • Procesas vykdomas tol, kol jis pats nepaliks procesoriaus, pereidamas į LAUKIMO būseną arba neįvyks klaida, arba procesas nepasibaigs.

  15. Algoritmo su santykiniais prioritetais būsenų grafas VYKDYMAS PARUOŠTAS LAUKIMAS

  16. Algoritmai, naudojantys absoliutinius prioritetus Sistemose, su absoliutiniais prioritetais, akty-vaus proceso vykdymas nutraukiamas dar vie-nu atveju: jeigu pasiruošusių procesų eilėje at-siranda procesas, kurio prioritetas aukštesnis, nei aktyvaus proceso. Šiuo atveju pertrauktas procesas pereina į PARUOŠTŲ būseną.

  17. Algoritmo su absoliutiniais prioritetais būsenų grafas b) VYKDYMAS PARUOŠTAS LAUKIMAS

  18. Pagrindiniai procesų planavimo procedūrų tipai • išstumiančios (preemptive), • neišstumiančios (non-preemptive).

  19. Neišstumiantis daugiaužduotiškumas • Neišstumiantis daugiaužduotiškumas (non-preemptive multitasking) – tai procesų pla-navimo būdas, kai aktyvus procesas vykdo-mas tol, kol jis pats (savo iniciatyva) neati-duos valdymo OS planuotojui, kad šis iš ei-lės išrinktų kitą, pasiruošusį vykdymui pro-cesą.

  20. Išstumiantis daugiaužduotiškumas • Išstumiantis daugiaužduotiškumas (preemp-tive multitasking) – tai toks būdas, kai sprendimą perjungti procesorių kito proceso vykdymui priima OS planuotojas, o ne pats aktyvus procesas.

  21. Process Hierarchies • Parent creates a child process, child processes can create its own process • Forms a hierarchy • UNIX calls this a "process group" • Windows has no concept of process hierarchy • all processes are created equal

  22. Process States (1) • Possible process states • running • blocked • ready • Transitions between states shown

  23. Process States (2) • Lowest layer of process-structured OS • handles interrupts, scheduling • Above that layer are sequential processes

  24. Implementation of Processes (1) Fields of a process table entry

  25. Implementation of Processes (2) Skeleton of what lowest level of OS does when an interrupt occurs

  26. Procesų sinchronizavimas ir sąveika Sinchronizavimo problema: • vienas procesas gali perduoti duomenis kitam, • keli procesai gali apdoroti duomenis iš bendro failo (bendrų resursų naudojimas).

  27. Procesų sinchronizavimas ir sąveika (2) Procesų sinchronizavimo problemos sprendimo būdai: • Procesų pristabdymas ir aktyvavimas, • Eilių organizavimas, • Resursų blokavimas ir atlaisvinimas.

  28. Sinchronizavimo uždavinio pvz. Procesas-klientas R R1 Perskaityti NEXT Užrašyti failo RFILE vardą Padidinti NEXT . . . Bendri duomenys Spausdinimo serveris R2 Failų iš sąrašo spausdinimas Užsakymų failas R3 ALPHA BETA GAMMA NEXT Procesas-klientas S S1 Perskaityti NEXT Užrašyti failo SFILE vardą Padidinti NEXT . . . S2 S3

  29. ThreadsThe Thread Model (1) (a) Three processes each with one thread (b) One process with three threads

  30. The Thread Model (2) • Items shared by all threads in a process • Items private to each thread

  31. The Thread Model (3) Each thread has its own stack

  32. Thread Usage (1) A word processor with three threads

  33. Implementing Threads in User Space A user-level threads package

  34. Implementing Threads in the Kernel A threads package managed by the kernel

  35. Hybrid Implementations Multiplexing user-level threads onto kernel- level threads

  36. Scheduler Activations • Goal – mimic functionality of kernel threads • gain performance of user space threads • Avoids unnecessary user/kernel transitions • Kernel assigns virtual processors to each process • lets runtime system allocate threads to processors • Problem: Fundamental reliance on kernel (lower layer) calling procedures in user space (higher layer)

  37. Interprocess CommunicationRace Conditions Two processes want to access shared memory at same time

  38. Critical Regions (1) Four conditions to provide mutual exclusion • No two processes simultaneously in critical region • No assumptions made about speeds or numbers of CPUs • No process running outside its critical region may block another process • No process must wait forever to enter its critical region

  39. Critical Regions (2) Mutual exclusion using critical regions

  40. SchedulingIntroduction to Scheduling (1) • Bursts of CPU usage alternate with periods of I/O wait • a CPU-bound process • an I/O bound process

  41. Introduction to Scheduling (2) Scheduling Algorithm Goals

  42. Iki cia

  43. Scheduling in Batch Systems (1) An example of shortest job first scheduling

  44. Scheduling in Batch Systems (2) Three level scheduling

  45. Scheduling in Interactive Systems (1) • Round Robin Scheduling • list of runnable processes • list of runnable processes after B uses up its quantum

  46. Scheduling in Interactive Systems (2) A scheduling algorithm with four priority classes

  47. Scheduling in Real-Time Systems Schedulable real-time system • Given • m periodic events • event i occurs within period Pi and requires Ci seconds • Then the load can only be handled if

  48. Policy versus Mechanism • Separate what is allowed to be done with how it is done • a process knows which of its children threads are important and need priority • Scheduling algorithm parameterized • mechanism in the kernel • Parameters filled in by user processes • policy set by user process

  49. Thread Scheduling (1) Possible scheduling of user-level threads • 50-msec process quantum • threads run 5 msec/CPU burst

More Related