1 / 59

Processes (Διεργασίες)

Processes (Διεργασίες). 2.1 Processes - Διεργασίες 2.2 Interprocess communication – Διαδιεργασιακή επικοινωνία 2.3 Classical IPC problems 2.4 Scheduling - Χρονοπρογραμματισμός. Chapter 2. Processes The Process Model.

baker-vang
Download Presentation

Processes (Διεργασίες)

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 (Διεργασίες) 2.1 Processes - Διεργασίες 2.2 Interprocess communication – Διαδιεργασιακή επικοινωνία 2.3 Classical IPC problems 2.4 Scheduling - Χρονοπρογραμματισμός Chapter 2

  2. ProcessesThe Process Model • Pseudo-parallelism: rapid switching back and forth of the CPU between programs • A process is an executing program + values of the PC+registers+variables. • Think the processes run in parallel – each on a separate CPU. • Independent sequential processes.

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

  4. ProcessesThe Process Model • Processes must not be programmed with built-in assumptions about timing. • E.g. an idle loop to wait for I/O reading. • Processes are NOT programs. • E.g. someone preparing a birthday cake following a recipe (=the program). The whole activity is the process.

  5. 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

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

  7. 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

  8. Process States - Καταστάσεις (1) • Process often need to interact with other processes. • E.g. cat chapter1 chapter2 chapter3 | grep tree • Three states: runnable, blocked, running (έτοιμη ή εκτελέσιμη, υπό αναστολή, εκτελούμενη) • Blocked != Runnable

  9. Process States (2) • Possible process states • running (using the CPU now) • blocked (unable to run until an event happens) • ready (runnable; temporarily stopped) • Transitions between states shown

  10. Process States (3) • Lowest layer of process-structured OS • handles interrupts, scheduling, i.e. scheduler does more than process scheduling • Above that layer are sequential processes

  11. Implementation of Processes (1) • To implement the process model the OS maintains the process table (πίνακας διεργασιών). There is one entry for each process, keeping the process state.

  12. Implementation of Processes (2) Fields of a process table entry

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

  14. Interprocess CommunicationRace Conditions (συνθήκες ανταγωνισμού) • Processes frequently communicate with other processes (IPC). • Processes share common storage (read/write). • Situations where two or more processes are reading or writing some shared data and the final result depends on who runs when are called race conditions. • E.g. printing and spooler directories.

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

  16. Critical Regions (1) – Κρίσιμα τμήματα • Prohibit more than one process to read/write • What is needed is mutual exclusion (αμοιβαίος αποκλεισμός) • Primitive operations to achieve mutual exclusion – a design choice for an OS • The part of the program that accesses shared memory is called critical region

  17. Critical Regions (2) 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

  18. Critical Regions (3) Mutual exclusion using critical regions

  19. Mutual Exclusion with Busy Waiting (1)Αμοιβαίος αποκλεισμός με ενεργό αναμονή • Disabling interrupts (απενεργοποίηση διακοπών): a process disables all the interrupts when entering the critical region and enabling them before exit • Lock variables (μεταβλητές κλειδώματος): A software solution. Unfortunately does not work. • Strict alternation (αυστηρή εναλλαγή) • Peterson’s solution • TSL instruction

  20. Mutual Exclusion with Busy Waiting (2)Strict Alternation Proposed solution to critical region problem (a) Process 0. (b) Process 1.

  21. Mutual Exclusion with Busy Waiting (3)Peterson’s solution Peterson's solution for achieving mutual exclusion

  22. Mutual Exclusion with Busy Waiting (4) TSL instruction= test and set lock – indivisible. Use of a shared variable, flag (could be 0 or 1). Entering and leaving a critical region using the TSL instruction

  23. Sleep and Wakeup (1) – Απενεργοποίηση και αφύπνιση • Previous solutions require busy waiting: • the waiting process sits in a tight loop • wastes CPU time • unexpected effects • A process may block instead of waiting • SLEEP and WAKEUP(pid) system calls • Example: producer and consumer (παραγωγός- καταναλωτής)

  24. Sleep and Wakeup (2) Producer-consumer problem with fatal race condition

  25. Semaphores(1) - Σημαφόροι • A semaphore can have the value 0 or > 0 • Two operations, DOWN and UP • DOWN: if semaphore > 0 then semaphore-- otherwise it sleeps (atomic action-all in one) • UP: increments the semaphore and waking up a process – again indivisible • DOWN and UP should be atomic • The producer-consumer problem using binary semaphores

  26. Semaphores(2)

  27. Monitors (1) - Παρακολουθητές • Semaphores are good but there are deadlocks. • A higher level of synchronization principle • A monitor is a collection of procedures, variables and data structures grouped together in a module or package. • Processes can call procedures of the monitor but can not access internal data structures. • !Only one process can be active in a monitor!

  28. Monitors (2) Example of a monitor

  29. Monitors (3) • Monitors are programming constructs => compilers job to implement (binary semaphores) • Monitors achieve mutual exclusion but processes must block when they can not proceed. • Condition variables (μεταβλητών συνθήκης) + WAIT + SIGNAL • Ensure: no two active processes in the monitor. • WAIT and SIGNAL are similar to SLEEP and WAKEUP, but without the known bug. • Problem: it is a programming language concept

  30. Monitors (4) • Outline of producer-consumer problem with monitors • only one monitor procedure active at one time • buffer has N slots

  31. Monitors (5) Solution to producer-consumer problem in Java (part 1)

  32. Monitors (6) Solution to producer-consumer problem in Java (part 2)

  33. Message Passing (1) – Μεταβίβαση μηνύματος • Uses 2 primitives: SEND, RECEIVE • SEND (destination, &message) • RECEIVE(source, &message) • These are system calls, like semaphores • Many interesting problems and design issues • lost messages • naming processes • authentication

  34. Message Passing (2) The producer-consumer problem with N messages

  35. Message Passing (3) • Implementing Message Passing: • buffers • Mailboxes - γραμματοκιβώτιο • Rendezvous – συνάντηση • pipes - σωληνώσεις

  36. Equivalence of Primitives (1) • Using semaphores to implement monitors • Associated with each monitor is a binary semaphore, mutex, initially 1, to control entry to the monitor and an additional semaphore, initially 0, per condition variable • Using semaphores to implement monitors • Associated with each process is a semaphore, initially 0, on which it will block when a SEND or RECEIVE must wait for completion.

  37. Equivalence of Primitives (2) • Using monitors to implement semaphores • Using monitors to implement message passing • Using message passing to implement semaphores • Using message passing to implement monitors

  38. Dining Philosophers (1) • Philosophers eat/think • Eating needs 2 forks • Pick one fork at a time • How to prevent deadlock

  39. Dining Philosophers (2) A nonsolution to the dining philosophers problem

  40. Dining Philosophers (3) • Modifications: • after taking the left fork, the program checks to see if the right fork is available. If not, put down the left fork and wait for some time. Starvation. • waiting random time – critical applications. • protect the five statements following the call to think by a binary semaphore. Performance problem.

  41. Dining Philosophers (4) Solution to dining philosophers problem (part 1)

  42. Dining Philosophers (5) Solution to dining philosophers problem (part 2)

  43. The Readers and Writers Problem (1) • Big database system (e.g. airline reservation) • Processes compete to write and read • Many readers concurrently • Only one writer at any time – no readers and writers

  44. The Readers and Writers Problem (2) A solution to the readers and writers problem

  45. The Sleeping Barber Problem (1)

  46. The Sleeping Barber Problem (2) Solution to sleeping barber problem.

  47. Scheduling- χρονοπρογραμματισμόςIntroduction to Scheduling (1) • Bursts of CPU usage alternate with periods of I/O wait • a CPU-bound process • an I/O bound process

  48. SchedulingIntroduction to Scheduling (1) • Schedulers, scheduling algorithms • Goals: fairness, efficiency, response time, turnaround, throughput (δικαιοσύνη, αποδοτικότητα, χρόνος απόκρισης, κύκλος διεκπεραίωσης, ρυθμός απόδοσης) • Processes are unique and unpredicatable • Preemptive scheduling vs. run to completion • Interactive systems vs. batch systems

  49. Introduction to Scheduling (2) Scheduling Algorithm Goals

  50. Round Robin Scheduling –Εκ περιτροπής • One of the oldest, fairest, most widely used algorithms • Each process is given a time interval, called quantum • Round Robin Scheduling • list of runnable processes • list of runnable processes after B uses up its quantum • Length of quantum could be too short or too long • Process switch or context switch

More Related