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

Slides:



Advertisements
Similar presentations
1 Processes and Threads Creation and Termination States Usage Implementations.
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Scheduling Introduction to Scheduling
Uniprocessor Scheduling Chapter 9 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved OPERATING SYSTEMS DESIGN.
Chapter 2 Processes and Threads
Mutual Exclusion.
Interprocess Communication
Operating Systems Operating Systems - Winter 2009 Chapter 2 - Processes Vrije Universiteit Amsterdam.
1 Friday, June 16, 2006 "In order to maintain secrecy, this posting will self-destruct in five seconds. Memorize it, then eat your computer." - Anonymous.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
EEE 435 Principles of Operating Systems Interprocess Communication Pt I (Modern Operating Systems 2.3)
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Avishai Wool lecture Priority Scheduling Idea: Jobs are assigned priorities. Always, the job with the highest priority runs. Note: All scheduling.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Review: Process Communication Sequential Communication –Result of P1 becomes at termination the input to P2 –Tools: Redirect (>,>>) and Pipe (|) Concurrent.
CMPT 300: Operating Systems Review THIS REIVEW SHOULD NOT BE USED AS PREDICTORS OF THE ACTUAL QUESTIONS APPEARING ON THE FINAL EXAM.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
CSCE 351: Operating System Kernels
Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
General What is an OS? What do you get when you buy an OS? What does the OS do? What are the parts of an OS? What is the kernel? What is a device.
Processes A program in execution.
Processes and Threads.
1 Process States (1) Possible process states –running –blocked –ready Transitions between states shown.
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
1 Processes Management 1 Processes 2 Threads 3 IPC problems 4 Processes Scheduling 5 Deadlock.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
操作系统原理 OPERATING SYSTEM Chapter 2 Processes and Threads 进程与线程.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Interprocess Communication Race Conditions
Operating Systems Chapter 2 - Processes Vrije Universiteit Amsterdam
Applied Operating System Concepts -
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 2 Scheduling.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Message Passing, Scheduler
Operating Systems Chapter 2: Processes and Threads
Processes and Threads Part III
Process Description and Control
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Concurrency: Mutual Exclusion and Process Synchronization
Process Description and Control
Chapter 6 Synchronization Principles
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
CS333 Intro to Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Presentation transcript:

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

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

Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential processes Only one program active at any instant

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

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

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

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

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

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

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

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.

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

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

Interprocess Communication Race 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.

Interprocess Communication Race Conditions Two processes want to access shared memory at same time

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

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

Mutual exclusion using critical regions

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

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

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

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

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 (παραγωγός- καταναλωτής)

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

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

Semaphores(2)

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!

Monitors (2) Example of a monitor

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

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

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

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

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

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

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

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 Associated with each process is a semaphore, initially 0, on which it will block when a SEND or RECEIVE must wait for completion.

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

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

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

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.

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

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

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

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

The Sleeping Barber Problem (1)

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

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

Scheduling Introduction 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

Introduction to Scheduling (2) Scheduling Algorithm Goals

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

Priority Scheduling (1) - Προτεραιότητες Round robin assumes all processes equal May have different groups with priorities Idea: Each process is assigned a priority and the runnable process with the highest priority is allowed to run The scheduler may decrease the priority of each process at each clock tick (Unix: nice) Priorities can be assigned dynamically (I/O)

Priority Scheduling (2) A scheduling algorithm with four priority classes

Multiple Queues – Πολλαπλές ουρές Set up priority classes Processes in the highest class run for one quantum. In the next highest class run for two quanta, four quanta, etc. Minimize swaps

Shortest Job First Mainly batch systems, running times are known An example of shortest job first scheduling: 14m 11m 4 jobs with running time: a,b,c,d. Completion time is: 4a+3b+2c+d. Minimum average response time. Can it be used for interactive processes?

Policy-Driven Scheduling – Εγγυημένος χρονοπρογραμματισμός Make promises to user and live up to them Example: if there are n users in the system you will get 1/n CPU power Keep track of how much CPU time a user has had for all his processes since login A similar idea can be applied to real-time systems where there are deadlines

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

Two Level Scheduling Some processes may have to be kept in disk. Major implications – Algorithms must change Two level-scheduler: Some subset of runnable processes into memory. Lower-level scheduler picks from these. Periodically a higher-level scheduler removes processes from main memory to disk and vice versa How long has it been since the process was swapped in/out How much CPU the has the process had recently? How big is the process? What is its priority?

Three Level Scheduling

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